5

我正在使用以下代码在我的 asp.net 应用程序中使用 ServiceStack 基本身份验证提供程序来验证用户并接收序列化异常。如果有人解决了这个问题,请回答。谢谢。

我在我的 asp.net 应用程序中使用以下代码:

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

我在文件后面的代码中收到有关clien.Post 方法的异常。

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;
            }
        }

Followin 是我在clien.Post 方法上收到的异常详细信息:

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

1 回答 1

1

Serialization exception that reads "expecting serialized type 'X', got string starting with:" means that the serializer tries to create an object from an empty string instead of a proper json-formatted string ("{Class:{Property:{Sub:value}}}").

In this case, most likely cause is server at baseUrl returning no response (interpreted as empty string) to a POST request. Misconfigured URL or exception on server side, maybe?

于 2014-01-21T19:27:38.620 回答