开发者

How to use collections when define DataContract?

开发者 https://www.devze.com 2023-02-11 09:12 出处:网络
I want to \'send\' collectio开发者_JAVA百科n that contain numbers ( double ). I try to add array to my DataContract but its fail ( thru exception .. when i remark the array type its work fine ).

I want to 'send' collectio开发者_JAVA百科n that contain numbers ( double ). I try to add array to my DataContract but its fail ( thru exception .. when i remark the array type its work fine ).

How can i do it ?

Thanks for any help.


Collection Serialization happens automatically only when the collection in the contract is a concrete collection (that is, not an interface) and is serializable (annotated with the Serializable attribute). If that is the case, WCF can automatically serialize the collection as an array of the collection’s type as long as the collection contains an Add operation. This holds true for both the built-in .NET collections and for any of your own custom collections that implement the IEnumerable or IEnumerable interface; as long as they are serializable and have an Add operation, they can be serialized to arrays automatically.

If your collection does not meet these constraints specify the CollectionDataContractAttribute.

[CollectionDataContract(Name = "MyCollectionOf{0}")]
0

精彩评论

暂无评论...
验证码 换一张
取 消