我正在使用以下代码来验证在我的 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;
}
}
以下是我在 clien.Post 方法上收到的异常详细信息:
[SerializationException: Type definitions should start with a '{', expecting serialized type 'AuthResponse', got string starting with:
最佳答案
序列化异常“期望序列化类型‘X’,字符串开头为:”意味着序列化程序尝试从空字符串而不是正确的 json 格式字符串创建对象 ("{Class: {属性:{Sub:值}}}“)。
在这种情况下,最可能的原因是 baseUrl 处的服务器没有对 POST 请求返回响应(解释为空字符串)。可能是 URL 配置错误或服务器端出现异常?
关于asp.net - 服务堆栈 :Type definitions should start with a '{' , 期望序列化类型 'AuthResponse' ,得到以以下开头的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16621459/