servicestackmessagepack

Unable to deserialize service response when using servicestack MsgPack client


Am getting below error when trying to deserialize the response from the service while using servicestack MsgPackServiceClient.

Exception: {"Cannot deserialize member 'test1' of type 'System.Int32'."}

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

Server side Servicestack Service:

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

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

Server side DTO:

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

Client Side code:

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

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

    }
}

Client side dto:

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

Client side we don't need Domain property. When we try to get the values, above exception is thrown.

When we add Domain property it works fine and we are able to get values.

Do we really need to have all the properties?

Please help me in solving this issue. Thanks for your time.


Solution

  • If you're using a Binary Format like MsgPack you should use the exact DTOs that were used for serialization which many Binary Serializers are designed to expect.

    If you just want to use a partial DTO on the client you should use a flexible Text Serializer like JSON instead.