2

当我向我的 ServiceStack 服务发出 POST 和 PUT 请求时(目前使用 HTTP 侦听器独立运行),我有时会发现该请求会起作用,有时我的客户端(HTTPie)会挂起。过了一会儿,我会在 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

我设法在 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

我正在提出这样的测试请求:-

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

这种确切的尝试有时会奏效,而另一些则失败。我正在使用带有 .NET4 和 VS 2010 的 NuGet 的最新 ServiceStack。看来该请求根本没有到达我自己的代码。

有谁知道可能导致这种情况的原因,或者我如何调试它?

编辑:不确定它是否相关,但有时我也得到这个:-

{

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

}
4

2 回答 2

3

看来 AVG Anti-Virus Business 是罪魁祸首。我知道我讨厌杀毒软件是有原因的!

我发现代码在另一台机器上运行良好,这告诉我这是我的开发箱设置所特有的。我尝试将机器剥离到最低限度,删除未使用的软件、VS 扩展、插件等。我为 ServiceStack 尝试了 IIS Express 和自托管模式。我尝试将我的代码移出 Dropbox。没有任何区别。

当我最终禁用 AVG 时,问题就消失了,几个小时后它仍然可以正常工作。

于 2012-09-28T10:08:27.950 回答
1

要调试,没有什么比下载项目源代码和调试框架源代码本身更好的了。我建议尝试在集成测试中复制此行为,以便我们找出导致它的原因。有关如何执行此操作的示例,请参阅 ServiceStack 的http 侦听器集成测试。

要在 ServiceStack 中启用日志记录,您只需在启动/初始化 AppHost 之前将日志工厂设置为您选择的提供者。

LogManager.LogFactory = new ConsoleLogFactory(typeof(Program));
于 2012-09-26T17:27:41.160 回答