Openrasta 数据序列化问题

发布于 2025-01-05 00:45:11 字数 1390 浏览 4 评论 0原文

我目前正在使用 openRasta 构建 Rest Api。我在发送 Ajax 请求时观察到奇怪的行为。有时请求成功,有时会失败,并给出以下异常。

{Exception:
System.Runtime.Serialization.SerializationException: Expecting element 'root' from namespace ''.. Encountered 'None'  with name '', namespace ''. 
   at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
   at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)
   at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(Stream stream)
   at OpenRasta.Codecs.JsonDataContractCodec.ReadFrom(IHttpEntity request, IType destinationType, String paramName)
   at OpenRasta.OperationModel.Hydrators.RequestEntityReaderHydrator.TryReadPayloadAsObject(IHttpEntity requestEntity, IMediaTypeReader reader, IOperation operation)}

我观察到的一件事是,当我让浏览器空闲一段时间(比如超过 10 分钟)时,我可以在 firebug 中看到该请求,但它显示状态为待处理很长时间,当它到达服务器时,它会给出上述异常。但同样工作正常有时。

有人可以向我解释这种行为吗?如果需要,我可以提供一些与之相关的附加代码。

I am currently using openRasta to build Rest Api.I am observing strange behavior while sending Ajax requests.Sometimes request is successful sometime it fails and it gives following exception.

{Exception:
System.Runtime.Serialization.SerializationException: Expecting element 'root' from namespace ''.. Encountered 'None'  with name '', namespace ''. 
   at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
   at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)
   at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(Stream stream)
   at OpenRasta.Codecs.JsonDataContractCodec.ReadFrom(IHttpEntity request, IType destinationType, String paramName)
   at OpenRasta.OperationModel.Hydrators.RequestEntityReaderHydrator.TryReadPayloadAsObject(IHttpEntity requestEntity, IMediaTypeReader reader, IOperation operation)}

One thing i have observed is that when i keep browser idle for some time say more than 10 minutes i can see the request in firebug but it shows status as pending for long time and when it hits server it gives above exception.But same works fine sometimes.

Can anybody explain me this behavior?If want i can provide some additional code related to it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈甜 2025-01-12 00:45:11

延迟可能只是由于当您最终摆脱空闲状态时 ASP.NET 必须重新启动而造成的,这需要一些时间。

至于错误,似乎是json数据契约序列化器无法解析请求。我建议检查一些事情,如果失败,请在此处发布详细信息,以便我们可以进一步帮助您。

  1. 错误发生时,主体确实是正确的(使用 fiddler)
  2. 您不存在一些特定于 ASP.NET 的问题,这些问题会阻止请求正确到达 ASP.NET 管道,例如基于 Cookie 的身份验证或会话管理
  3. 该请求不会被任何 http 模块(防伪造令牌等)拦截。

请提供您的映射、实体和 OR 日志的副本(您可以通过将调试器附加到服务器进程来获取),我们将尽力为您提供进一步帮助。

The delay may just be caused by asp.net having to restart when you finally get out of idle, which takes a little while.

As for the error, it seems to be that the json data contract serializer can't parse the request. I'd advise to check a couple of things, and if it fails post here the details so we can help you further.

  1. That the body is indeed correct at the time the error is triggererd (with fiddler)
  2. That you do not have some asp.net-specific issues that would prevent the request from arriving correctly to the asp.net pipeline, such as cookies-based authentication or session management
  3. That the request is not intercepted by any http module (anti forgery tokens etc).

Please provide your mappings, entities and a copy of the OR log (which you can get by attaching a debugger to the server process) and we'll try and help you further.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文