Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose my collection from the Web Service (WCF)

Tags:

wcf

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.

like image 291
Ashish Ashu Avatar asked Jul 28 '09 06:07

Ashish Ashu


People also ask

How can I access WCF service?

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.

Is WCF SOAP or REST?

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.

What is difference between web service and WCF?

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.


1 Answers

You'll need to use the CollectionDataContract attribute to handle this in WCF.

[CollectionDataContract] 
public class MyCollection : IDisposable, List<MyClass> 
{
}

Marc

like image 87
marc_s Avatar answered Nov 16 '22 02:11

marc_s