I have a small test web service to emulate something strange that I notice in a real world application. Since the demo demonstrates the same behavior as the application, I will use the demo for brevity.
In short, my service interface file looks like this (as you can see, this is the default WCF service created by VS2008, but I added a new public method (GetOtherType ()) and two new classes below (SomeOtherType and SomeComplexType) SomeOtherType manages a generic list like SomeComplexType
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace WCFServiceTest { [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); [OperationContract] SomeOtherType GetOtherType(); } [DataContract] public class CompositeType { bool boolValue = true; string stringValue = "Hello "; [DataMember] public bool BoolValue { get { return boolValue; } set { boolValue = value; } } [DataMember] public string StringValue { get { return stringValue; } set { stringValue = value; } } } [DataContract] public class SomeOtherType { public List<SomeComplexType> Items { get; set; } } [DataContract] public class SomeComplexType { } }
My service is implemented as follows
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace WCFServiceTest { public class Service1 : IService1 { #region IService1 Members public string GetData(int value) { throw new NotImplementedException(); } public CompositeType GetDataUsingDataContract(CompositeType composite) { throw new NotImplementedException(); } #endregion #region IService1 Members public SomeOtherType GetOtherType() { throw new NotImplementedException(); } #endregion } }
The problem is that if I include a service link to this service in an ASP.NET web application, I cannot see SomeComplexType through intellisense. The error is because the type or namespace was not found. However, SomeOtherType can be found (I assume the type is the return type from one of the public methods).
Do I understand correctly that I cannot expose a type from the WCF service if this type is not specified in the method signature of one of my public methods (return type or argument)? If so, how could I iterate over the elements inside the SomeOtherType instance on the client?
Thanks a lot, and I hope this is understandable.
Simon
source share