简体   繁体   English

WCF检查邮件

[英]WCF Inspect Messages

I'm trying to implement a simple message inspector that writes the message to the debug window from an example on MSDN : 我正在尝试实现一个简单的消息检查器,它将消息从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. 但是请求似乎是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. 我正在使用basicHttpbinding并使用svc文件托管IIS。 The parameter for my web method is a complex type. 我的Web方法的参数是一个复杂的类型。 I'm not sure if that makes a difference. 我不确定这是否有所作为。

Try CreateBufferedCopy (ie clone) of the message request first: http://msdn.microsoft.com/en-us/library/ms734675.aspx (Copying a Message into a Buffer). 首先尝试消息请求的CreateBufferedCopy(即克隆): http//msdn.microsoft.com/en-us/library/ms734675.aspx (将消息复制到缓冲区)。

More info here under "Now for the message inspection part": http://binarymist.net/2010/06/14/message-inspection-in-wcf/ 更多信息请点击“现在的邮件检查部分”: http//binarymist.net/2010/06/14/message-inspection-in-wcf/

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. 我复制并粘贴了MyMessageInspector类并将行为添加到我的Web服务中,并且工作正常 - 调用Web服务时,SOAP信封将打印为XML。

Do you have any other MessageInspectors in your project? 你的项目中还有其他MessageInspectors吗? 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 is ref . 如果是这样,其中一个可能是设置request = null - 这将导致您遇到的问题,因为请求参数是ref

If not, what makes you say request is null? 如果没有,是什么让你说请求是空的? Are you getting a NullReferenceException on the Debug.WriteLine(..) statement? 你在Debug.WriteLine(..)语句中得到NullReferenceException吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM