当我向我的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
这种确切的尝试有一段时间,并使其他人失败。 我正在使用NuGet的最新ServiceStack与.NET4和VS 2010。 似乎请求根本没有达到我自己的代码。
有谁知道可能导致这种情况的原因,或者我如何调试它?
编辑:不确定它是否相关,但有时我也会这样: -
{
"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"
}
}
答案 0 :(得分:3)
似乎AVG Anti-Virus Business是罪魁祸首。我知道我讨厌反病毒软件是有原因的!
我发现代码在另一台机器上工作正常,它告诉我这是我的开发箱设置特有的。我尝试将机器剥离到最低限度,删除未使用的软件,VS扩展,插件等。我尝试了IIS Express和ServiceStack的自托管模式。我尝试将我的代码移出Dropbox。没有任何区别。
当我最终禁用AVG时,问题就消失了,几个小时之后它仍然完美无缺。
答案 1 :(得分:1)
要进行调试,不需要下载project source code并调试框架源代码本身。我建议尝试在集成测试中复制此行为,以便我们可以找出导致它的原因。有关如何执行此操作的示例,请参阅ServiceStack的http listener integration tests。
要在ServiceStack中启用日志记录,您只需在开始/初始化AppHost之前将日志工厂设置为provider of your choice。
LogManager.LogFactory = new ConsoleLogFactory(typeof(Program));