Is there any way to get ServiceStack to deserialize complex types on a Silverlight client?

只愿长相守 提交于 2019-12-24 02:45:30

问题


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



来源:https://stackoverflow.com/questions/13851744/is-there-any-way-to-get-servicestack-to-deserialize-complex-types-on-a-silverlig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!