WCF deserialization returns 0 list items

I am having trouble deserializing the object.

I have the following classes:

Metadatastore:

[DataContract] public class MetadataStore : IEnumerable<ItemMetadata> { private List<ItemMetadata> data = new List<ItemMetadata>(); private string folderPath = null; [DataMember] public string FilePath { // getter and setter } [DataMember] public List<ItemMetadata> Data { // getter and setter } } 

ItemMetadata:

 [Serializable()] public class ItemMetadata { // syncid, syncversion, uristring etc.. } 

Problem:

I am passing the Metadatastore object from my server (which works with the wcf service) to my client using the output parameter. Thus, serialization / deserialization of this output parameter is done automatically by wcf. Here's what happens:

the client calls the service:

 service.GetChangeBatch(out metadatastore_object, otherValue); 

the server responds correctly (metadatastore_object is full and serialized successfully β†’ no errors)

the object that I get on the client side is incorrect: FilePath is filled correctly, but the Data List object contains null elements! I also checked on the server and the data list contained 2 items. Another strange thing that should be noted is that it is not zero, it is just a newly created empty list. Does anyone have any experience with this, I can provide more code if necessary. Thanks in advance. Salutes Daan

+4
source share
4 answers

Use CollectionDataContract instead of DataContract .

Here's an msdn explanation about CollectionDataContract : http://msdn.microsoft.com/en-us/library/aa347850.aspx

+1
source

It could be a line:

  private List<ItemMetadata> data = new List<ItemMetadata>(); 

This is emptying your list.

Also I would tag ItemMetadata with a DataContract and all properties with a DataMember.

0
source

The ItemMetadata class also needs to be decorated as a DataContract so that the client knows about the type and how to deserialize it.

0
source

You can also enable verbose message logging in the wcf service to find out which SOAP xml is being returned from the server.

Then you can find out if the client doesn’t deserialize the xml for the correct object or if the server serializes the object in xml incorrectly.

NTN

0
source

Source: https://habr.com/ru/post/1393195/


All Articles