【问题标题】:Unable to deserialize service response when using servicestack MsgPack client使用 servicestack MsgPack 客户端时无法反序列化服务响应
【发布时间】:2016-10-22 09:07:10
【问题描述】:

在使用 servicestack MsgPackServiceClient 时尝试反序列化来自服务的响应时出现以下错误。

异常:{“无法反序列化类型为‘System.Int32’的成员‘test1’。”}

InnerException : {"Cannot convert 'System.Int32' type value from type 'FixedRaw'(0xA4) in offset 1."}

服务器端Servicestack服务:

    public class TestService : Service
    {
        public test Get(test s)
        {

            return new test { test1 = 12, test2 = "testvalue", Domian = "1234" };
        }
    }

服务器端 DTO:

[Route("/test")]
public class test
{
    public int test1 { get; set; }
    public string test2 { get; set; }
    public string Domain { get; set; }
}

客户端代码:

class Program
{
    static void Main(string[] args)
    {
        MsgPackServiceClient c = new MsgPackServiceClient(@"http://localhost:52862/");

        var result = c.Get<test>(@"/test");

    }
}

客户端dto:

public class test
{
    public int test1 { get; set; }
    public string test2 { get; set; }
}

客户端我们不需要域属性。当我们尝试获取值时,会抛出上述异常。

当我们添加域属性时,它可以正常工作并且我们能够获取值。

我们真的需要拥有所有属性吗?

请帮我解决这个问题。谢谢你的时间。

【问题讨论】:

    标签: servicestack messagepack


    【解决方案1】:

    如果您使用像 MsgPack 这样的二进制格式,您应该使用 exact 用于序列化的 DTO,这是许多二进制序列化程序设计所期望的。

    如果您只想在客户端上使用部分 DTO,您应该使用灵活的文本序列化器,例如 JSON。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      相关资源
      最近更新 更多