如何从Web服务(WCF)公开我的集合

时间:2023-01-15 15:46:07

I have a custom collection which i want to expose from the WCF web service.

我有一个自定义集合,我想从WCF Web服务公开。

[DataContract( Name = "MyClass")]
public class MyCollection : IDisposable, List<MyClass> 
{
}

When I use [DataContract( Name = "MyClass")] attribute it gives error

当我使用[DataContract(Name =“MyClass”)]属性时,它会给出错误

Type MyCollection is an invalid collection type since it has DataContractAttribute attribute.

类型MyCollection是一种无效的集合类型,因为它具有DataContractAttribute属性。

1 个解决方案

#1


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

您需要使用CollectionDataContract属性在WCF中处理此问题。

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

Marc

#1


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

您需要使用CollectionDataContract属性在WCF中处理此问题。

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

Marc