WCF 检查消息
我正在尝试实现一个简单的消息检查器,该检查器将示例中的消息写入调试窗口 MSDN:
public class MyMessageInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
System.Diagnostics.Debug.WriteLine(request.ToString());
return null;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
System.Diagnostics.Debug.WriteLine(reply.ToString());
}
}
回复按预期写入。然而,该请求似乎为空。关于可能出什么问题的任何想法吗?我使用服务引用代理和控制台应用程序作为客户端。
我正在使用 basicHttpbinding 并通过带有 svc 文件的 IIS 进行托管。我的 Web 方法的参数是复杂类型。我不确定这是否有影响。
I'm trying to implement a simple message inspector that writes the message to the debug window from an example on MSDN:
public class MyMessageInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
System.Diagnostics.Debug.WriteLine(request.ToString());
return null;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
System.Diagnostics.Debug.WriteLine(reply.ToString());
}
}
The reply is writing as expected. However the request seems to be null. Any ideas on what could be going wrong? I'm using a Service Reference proxy with a console app as the client.
I'm using basicHttpbinding and hosting with IIS with svc file. The parameter for my web method is a complex type. I'm not sure if that makes a difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先尝试 CreateBufferedCopy(即克隆)消息请求: http://msdn.microsoft .com/en-us/library/ms734675.aspx(将消息复制到缓冲区)。
更多信息请参见“现在进行消息检查部分”: http:// /binarymist.net/2010/06/14/message-inspection-in-wcf/
Try CreateBufferedCopy (i.e clone) of the message request first: http://msdn.microsoft.com/en-us/library/ms734675.aspx (Copying a Message into a Buffer).
More info here under "Now for the message inspection part": http://binarymist.net/2010/06/14/message-inspection-in-wcf/
我已复制并粘贴 MyMessageInspector 类,并将行为添加到我的 Web 服务中,并且它工作正常 - 当调用 Web 服务时,SOAP 信封将打印为 XML。
您的项目中还有其他 MessageInspector 吗?如果是这样,其中一个可能正在设置
request = null
- 这将导致您遇到的问题,因为请求参数是ref
。如果不是,是什么让你说请求为空?您是否在
Debug.WriteLine(..)
语句中收到 NullReferenceException?I have copy and pasted the MyMessageInspector class and added the behavior to my my web service, and it works fine - when the web service is called, the SOAP envelope is printed as XML.
Do you have any other MessageInspectors in your project? If so, it is possible that one of them is setting
request = null
- this will cause the problem you're having, since the request parameter isref
.If not, what makes you say request is null? Are you getting a NullReferenceException on the
Debug.WriteLine(..)
statement?