I have a custom collection which i want to expose from the WCF web service.
[DataContract( Name = "MyClass")]
public class MyCollection : IDisposable, List<MyClass>
{
}
When I use [DataContract( Name = "MyClass")]
attribute it gives error
Type MyCollection is an invalid collection type since it has DataContractAttribute attribute.
With the service running, right click the project that will contain the WCF client proxy and select Add > Service Reference. In the Add Service Reference Dialog, type in the URL to the service you want to call and click the Go button. The dialog will display a list of services available at the address you specify.
Normally, a WCF service will use SOAP, but if you build a REST service, clients will be accessing your service with a different architectural style (calls, serialization like JSON, etc.). Exposing a WCF service with both SOAP and REST endpoints, requires just a few updates to the codebase and configuration.
Attributes − WCF service is defined by ServiceContract and OperationContract attributes, whereas a web service is defined by WebService and WebMethod attributes. Protocols − WCF supports a range of protocols, i.e., HTTP, Named Pipes, TCP, and MSMQ, whereas a web service only supports HTTP protocol.
You'll need to use the CollectionDataContract attribute to handle this in WCF.
[CollectionDataContract]
public class MyCollection : IDisposable, List<MyClass>
{
}
Marc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With