问题描述
我想反序列化来自 Silverlight 客户端的 JSON 响应.
I want to deserialise a JSON response from a Silverlight client.
我的 DTO 位于可移植类库中,从服务器和客户端都引用.
I have my DTOs in a Portable Class Library, referenced from both server and client.
public class MyDTOResponse
{
public IEnumerable<MyType> ResponseData {get; set; }
}
当我使用 ServiceStack C# 客户端(即不是来自 Silverlight)时,一切正常:MyType 在客户端上得到水合.
When I use the ServiceStack C# client (ie NOT from Silverlight), everything works fine: MyType gets hydrated on the client.
来自 Silverlight,但是 ResponseData 为空.
From Silverlight, however ResponseData is null.
简单类型在 Silverlight 中也能正常工作.例如,这有效:
Simple types work fine from Silverlight also. For example, this works:
public class MyDTOResponse
{
public IEnumerable<string> ResponseData {get; set; }
}
注意:DTO 上没有注释.
Note: no annotations on the DTOs.
在客户端,我使用:
var serviceClient = new ServiceStack.ServiceClient.Web.JsonServiceClient(baseUri);
我的解决方法是更改 DTO,使其仅使用简单类型,然后在客户端手动混合我的业务对象.
My work around is to change the DTOs so they use just simple types, then manually hydrate my business objects on the client.
我能做得更好吗?
推荐答案
尝试将 [DataContract] 属性添加到类 MyDTOResponse 和 [DataMember] 属性到属性 ResponseData
Try adding [DataContract] Attribute to the class MyDTOResponse and [DataMember] Attribute to the Property ResponseData
这篇关于有没有办法让 ServiceStack 在 Silverlight 客户端上反序列化复杂类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!