2016-10-22 27 views
2

在使用服務堆棧MsgPackServiceClient嘗試反序列化服務響應時,出現低於錯誤的錯誤。使用服務堆棧MsgPack客戶端時,無法反序列化服務響應

異常:{ 「不能反序列化類型 'System.Int32' 的成員 'TEST1'。」}

的InnerException:{「不能從在型 'FixedRaw'(0xA4)轉換 'System.Int32' 的類型值偏移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; } 
} 

客戶端。當我們嘗試獲取值時,會引發上面的異常。

當我們添加域屬性,它工作正常,我們能夠獲得值。

我們是否真的需要擁有所有的屬性?

請幫我解決這個問題。謝謝你的時間。

回答

0

如果您使用的是二進制格式像MsgPack你應該使用被用於許多二進制序列化旨在期望系列化的確切的DTO。

如果您只是想在客戶端上使用部分DTO,則應該使用JSON等靈活的文本序列化程序。

+0

謝謝@Mythz – Shan

相關問題