我在序列化异常时访问WCF服务中的消息

时间:2012-07-13 22:24:59

标签: .net json wcf rest ierrorhandler

在WCF服务中,我有自定义IErrorHandler。工作得很好,我通过记录错误修复了很多东西。我得到的最后一个错误是序列化异常:

Unexpected end of file. Following elements are not closed: Source, item, root.

There was an error deserializing the object of type System.Collections.Generic.List`1[[My.Web.Services.Dto.Log, My.Web.Services.Dto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]. Unexpected end of file. Following elements are not clo

这告诉我消息没有从客户端正确传入。有什么方法可以看到它是什么信息吗?我可以从IErrorHandler内部访问HTTP post paramteres吗?

2 个答案:

答案 0 :(得分:1)

在将响应消息传递给发生序列化的channgel堆栈之前,会调用

IErrorHandler。因此,如果序列化遇到问题,则不会调用自定义错误处理程序。最好的办法是使用tracing记录消息并进行检查。

答案 1 :(得分:0)

创建一个WCF MessageInspector,(IDispatchMessageInspector),它允许您在反序列化之前访问该消息,请参阅链接示例中的AfterReceiveRequest方法。 Ian Picknell有一个更长的post更多细节