简体   繁体   English

对ServiceStack的PUT / POST请求挂起

[英]PUT/POST requests to ServiceStack hanging

When I make POST and PUT requests to my ServiceStack services (running standalone with an HTTP listener at the moment) I sometimes find that the request will work, and sometimes my client (HTTPie) will hang. 当我向ServiceStack服务发出POST和PUT请求(此刻正在使用HTTP侦听器独立运行)时,有时会发现请求可以正常工作,有时我的客户端(HTTPie)将挂起。 After a while I'll see some info in the Output window in Visual Studio:- 一段时间后,我会在Visual Studio的“输出”窗口中看到一些信息:

A first chance exception of type 'System.Net.HttpListenerException' occurred in System.dll
A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in ServiceStack.dll
A first chance exception of type 'System.Net.HttpListenerException' occurred in System.dll
A first chance exception of type 'System.Net.HttpListenerException' occurred in ServiceStack.dll
A first chance exception of type 'System.Net.HttpListenerException' occurred in ServiceStack.dll
A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in ServiceStack.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll

I managed to enable the built-in logging in ServiceStack and it gave more details:- 我设法在ServiceStack中启用了内置日志记录,它提供了更多详细信息:

ERROR: Error occured while Processing Request: Could not deserialize 'application/json; charset=utf-8' 
   request using WebServices.Dto.Country'
Error: System.Net.HttpListenerException (0x80004005): The I/O operation has been aborted because of either
    a thread exit or an application request
  at System.Net.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 size)
  at System.IO.StreamReader.ReadBuffer()
  at System.IO.StreamReader.ReadToEnd()
  at ServiceStack.Text.JsonSerializer.DeserializeFromStream(Type type, Stream stream) in C:\src\ServiceStack.Text\
   src\ServiceStack.Text\JsonSerializer.cs:line 164
  at ServiceStack.ServiceModel.Serialization.JsonDataContractDeserializer.DeserializeFromStream(Type type, Stream 
   stream) in C:\src\ServiceStack\src\ServiceStack.Common\ServiceModel\Serialization\JsonDataContractDeserializer.cs:line 86
  at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest httpReq, 
   Type requestType, String contentType) in C:\src\ServiceStack\src\ServiceStack\WebHost.Endpoints\Support\
   EndpointHandlerBase.cs:line 100, 
Exception: Could not deserialize 'application/json; charset=utf-8' request using WebServices.Dto.Country'
Error: System.Net.HttpListenerException (0x80004005): The I/O operation has been aborted because of either a thread
   exit or an application request
  at System.Net.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 size)
  at System.IO.StreamReader.ReadBuffer()
  at System.IO.StreamReader.ReadToEnd()
  at ServiceStack.Text.JsonSerializer.DeserializeFromStream(Type type, Stream stream) in C:\src\ServiceStack.Text\src\
   ServiceStack.Text\JsonSerializer.cs:line 164
  at ServiceStack.ServiceModel.Serialization.JsonDataContractDeserializer.DeserializeFromStream(Type type, Stream 
   stream) in C:\src\ServiceStack\src\ServiceStack.Common\ServiceModel\Serialization\JsonDataContractDeserializer.cs:line 86
  at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest httpReq, 
   Type requestType, String contentType) in C:\src\ServiceStack\src\ServiceStack\WebHost.Endpoints\Support\EndpointHandlerBase.cs:line 100
ERROR: Could not WriteTextToResponse: An operation was attempted on a nonexistent network connection, Exception: 
   An operation was attempted on a nonexistent network connection
ERROR: Could not WriteTextToResponse: An operation was attempted on a nonexistent network connection, Exception: 
   An operation was attempted on a nonexistent network connection
INFO: Failed to write error to response: {0}, Exception: An operation was attempted on a nonexistent network connection

I am making my test requests like this:- 我正在这样发出测试请求:

http --json post "http://localhost:1337/countries/" DefaultHouse_Id=2 Name=Denmark

This exact attempt works some time and fails others. 这种确切的尝试会花费一些时间,而会使另一些失败。 I'm using the latest ServiceStack from NuGet with .NET4 and VS 2010. It appears that the request does not reach my own code at all. 我正在使用带有.NET4和VS 2010的来自NuGet的最新ServiceStack。似乎该请求根本无法到达我自己的代码。

Does anyone know what could cause this, or how I can debug it? 有谁知道是什么原因造成的,或者我怎么调试它?

Edit: Not sure if it's related or not, but sometimes I also get this:- 编辑:不确定是否相关,但有时我也会得到:

{

"ResponseStatus":{

 "ErrorCode":"TypeLoadException",
 "Message":"Could not load type 'ServiceStack.ServiceInterface.HttpRequestApplyToExtensions' from assembly 'ServiceStack.ServiceInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.",
"StackTrace":"   at RulesLayer.AuditFilterAttribute.Execute(IHttpRequest req, IHttpResponse res, Object requestDto)\n   at     ServiceStack.ServiceInterface.RequestFilterAttribute.RequestFilter(IHttpRequest req, IHttpResponse res, Object requestDto) in C:\\src\\ServiceStack\\src\\ServiceStack.ServiceInterface\\RequestFilterAttribute.cs:line 41\n   at ServiceStack.WebHost.Endpoints.EndpointHost.ApplyRequestFilters(IHttpRequest httpReq, IHttpResponse httpRes, Object requestDto) in C:\\src\\ServiceStack\\src\\ServiceStack\\WebHost.Endpoints\\EndpointHost.cs:line 303\n   at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName) in C:\\src\\ServiceStack\\src\\ServiceStack\\WebHost.Endpoints\\RestHandler.cs:line 63"
}

}

It appears AVG Anti-Virus Business was the culprit. 看来是AVG Anti-Virus业务的元凶。 I knew I hated anti-virus software for a reason! 我知道我讨厌杀毒软件是有原因的!

I discovered that the code worked fine on another machine, which told me that it was something specific to my dev box setup. 我发现该代码在另一台机器上运行良好,这告诉我这是我的开发箱设置所特有的。 I tried stripping the machine back to bare minimum, removing unused software, VS extensions, plugins etc. I tried both IIS Express and self-hosted modes for ServiceStack. 我尝试将计算机恢复到最低限度,删除未使用的软件,VS扩展,插件等。我尝试了IIS Express和ServiceStack的自托管模式。 I tried moving my code out of Dropbox. 我尝试将代码移出Dropbox。 Nothing made any difference. 没有任何区别。

When I finally disabled AVG, the problem just vanished and several hours later it's still working perfectly. 当我最终禁用AVG时,问题消失了,几个小时后,它仍然运行正常。

To debug, nothing beats downloading the project source code and debugging the framework source code itself. 要进行调试,最好下载项目源代码并调试框架源代码本身。 I recommend trying to replicate this behavior in an integration test so we can find out what's causing it. 我建议尝试在集成测试中复制此行为,以便我们找出造成此问题的原因。 See ServiceStack's http listener integration tests for examples on how to do this. 有关如何执行此操作的示例,请参见ServiceStack的http侦听器集成测试

To enable logging in ServiceStack you just need set the log factory to be the provider of your choice before you start/initialize the AppHost. 要在ServiceStack中启用日志记录,您只需要在启动/初始化AppHost之前将日志工厂设置为您选择提供者即可。

LogManager.LogFactory = new ConsoleLogFactory(typeof(Program));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM