Ashish Ashu
Ashish Ashu

Reputation: 14667

How to expose my collection from the Web Service (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.

Upvotes: 14

Views: 3234

Answers (1)

marc_s
marc_s

Reputation: 754488

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

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

Marc

Upvotes: 29

Related Questions