Is there any way to get ServiceStack to deserializ

2019-07-11 14:28发布

问题:

I want to deserialise a JSON response from a Silverlight client.

I have my DTOs in a Portable Class Library, referenced from both server and client.

public class MyDTOResponse
{
    public IEnumerable<MyType> ResponseData {get; set; }
}

When I use the ServiceStack C# client (ie NOT from Silverlight), everything works fine: MyType gets hydrated on the client.

From Silverlight, however ResponseData is null.

Simple types work fine from Silverlight also. For example, this works:

public class MyDTOResponse
{
    public IEnumerable<string> ResponseData {get; set; }
}

Note: no annotations on the DTOs.

On the client, I am using:

var serviceClient = new ServiceStack.ServiceClient.Web.JsonServiceClient(baseUri);

My work around is to change the DTOs so they use just simple types, then manually hydrate my business objects on the client.

Can I do better than this?

回答1:

Try adding [DataContract] Attribute to the class MyDTOResponse and [DataMember] Attribute to the Property ResponseData