加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 服务栈:类型定义应该以'{‘开头,期望序列化类型

发布时间:2020-12-16 03:22:59 所属栏目:asp.Net 来源:网络整理
导读:我正在使用以下代码来验证用户在我的asp.net应用程序中使用ServiceStack基本身份验证提供程序并接收serration异常.如果有人解决了这个问题,请回答.谢谢. 我在我的asp.net应用程序中使用以下代码: asp:Button ID="btnAuth" runat="server" OnClick="btnAuth_
我正在使用以下代码来验证用户在我的asp.net应用程序中使用ServiceStack基本身份验证提供程序并接收serration异常.如果有人解决了这个问题,请回答.谢谢.

我在我的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方法上收到的Exeception Detail:

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

解决方法

序列化异常读取“期望序列化类型’X’,得到字符串以:开头”意味着序列化程序尝试从空字符串而不是正确的json格式字符串创建对象(“{Class:{Property:{Sub:值}}}”).

在这种情况下,最可能的原因是baseUrl上的服务器没有向POST请求返回任何响应(解释为空字符串).可能是服务器端配置错误的URL或异常?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读