來自Android設備的一些要求,使我們的服務servicestack.net失敗與此異常:Servicestack SerializationException:無法反序列化「應用/ JSON的」
System.Runtime.Serialization.SerializationException: Could not deserialize 'application/json' request using CSharpRequestMappedObject'
Error: System.Threading.ThreadAbortException: Thread was being aborted.
at System.Web.Hosting.UnsafeIISMethods.MgdSyncReadRequest(IntPtr pHandler, Byte[] pBuffer, Int32 offset, Int32 cbBuffer, Int32& pBytesRead)
at System.Web.Hosting.IIS7WorkerRequest.ReadEntityCoreSync(Byte[] buffer, Int32 offset, Int32 size)
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.get_InputStream()
at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest httpReq, Type requestType, String contentType)
at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest httpReq, Type requestType, String contentType)
at ServiceStack.WebHost.Endpoints.RestHandler.GetRequest(IHttpRequest httpReq, IRestPath restPath)
at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName)
我知道它有somethink做的Post'ed JSON數據不能被分析到CSharpRequestMappedObject。
這樣映射:
[Route("/RequestPath/", Verbs = "POST"), UsedImplicitly]
public class CSharpRequestMappedObject
{
public string Name{ get; set; }
public IList<SomeClass> Items{ get; set; }
public bool State { get; set; }
public string SpecialType { get; set; } //Not required
}
我的問題是我怎麼弄清楚什麼是錯的要求嗎?
它只是有時會發生 - 我看到它在我的服務器日誌中,但我無法重現它。
我在Global.asax中嘗試這樣:
public override void Configure(Container container)
{
ServiceExceptionHandler = (request, ex) =>
{
//Enrich exceptions with request body data.
var propertyInfo = HttpContext.Current.Request.GetType().GetProperty("EntityBody", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
var postBody = Encoding.UTF8.GetString((byte[])propertyInfo.GetValue(HttpContext.Current.Request, null));
throw new Exception("Request body: " + postBody, ex);
};
}
它增加了對其他異常請求體數據 - 但這種異常沒有逮住那裏。 (我有一個捕獲異常後一些其他日誌 - ELMAH)
感謝您的回答 - 我們結束瞭解,原因是請求的超時。 –