2013-05-18 13 views
5

開頭我使用以下代碼來驗證用戶在我的asp.net應用程序中使用ServiceStack基本身份驗證提供程序並接收serilization exception.Please回答如果有人解決了這個問題,謝謝。服務堆棧:類型定義應以'{'開頭,期望序列化類型'AuthResponse',得到的字符串以

我用我的asp.net應用程序下面的代碼:

<asp:Button ID="btnAuth" runat="server" OnClick="btnAuth_Click" Text="Authenticate"/> 

我在隱藏文件中的代碼上clien.Post方法 recieving例外。

protected void btnAuth_Click(object sender, EventArgs e) 
     { 
      try 
      {     
       var baseUrl = Request.Url.GetLeftPart(UriPartial.Authority) + "/api"; 
       var client = new JsonServiceClient(baseUrl); 
       var authResponse = client.Post<AuthResponse>(new Auth { UserName = "admin", Password = "12345" }); 
       if (authResponse.ResponseStatus.ErrorCode == null) 
       { 
        //Do Something here 
       } 
      } 
      catch (WebServiceException ex) 
      { 
       throw ex; 
      } 
     } 

富林偉業是我在clien.Post方法 recieving Exeception詳細信息:

[SerializationException: Type definitions should start with a '{', expecting serialized type 'AuthResponse', got string starting with: 
+0

看看這個帖子上接受的答案:http://stackoverflow.com/questions/12064166/how-to-use-servicestack-authentication-correctly-in-asp-net-mvc-controller希望可以幫助。 –

+0

@DavidTansey,這與手頭的問題有什麼關係?我遇到了同樣的錯誤,我甚至沒有使用任何Web應用程序。問題在於對象序列化不是關於認證。 –

+0

這個問題與MVC有關?如果不是,你可以糾正標籤嗎?謝謝 – Javier

回答

1

序列化異常,上面寫着 「期待系列化型 'X',得到字符串開頭:」 是指串行器嘗試從空字符串而不是正確的json格式的字符串(「{Class:{Property:{Sub:value}}}」「創建一個對象。

在這種情況下,最有可能的原因是服務器在baseUrl未向POST請求返回響應(解釋爲空字符串)。在服務器端配置錯誤的URL或異常,也許?

相關問題