【问题标题】:Is there any way to get ServiceStack to deserialize complex types on a Silverlight client?有什么方法可以让 ServiceStack 反序列化 Silverlight 客户端上的复杂类型?
【发布时间】:2013-06-05 20:46:36
【问题描述】:

我想反序列化来自 Silverlight 客户端的 JSON 响应。

我的 DTO 在可移植类库中,从服务器和客户端都引用。

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

当我使用 ServiceStack C# 客户端(即不是来自 Silverlight)时,一切正常:MyType 在客户端上得到补充。

来自 Silverlight,但 ResponseData 为空。

Silverlight 中的简单类型也可以正常工作。例如,这有效:

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

注意:DTO 上没有注释。

在客户端,我正在使用:

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

我的解决方法是更改​​ DTO,使它们仅使用简单类型,然后在客户端手动合并我的业务对象。

我能做得比这更好吗?

【问题讨论】:

标签: c# silverlight servicestack


【解决方案1】:

尝试将 [DataContract] 属性添加到类 MyDTOResponse 和 [DataMember] 属性到属性 ResponseData

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多