从和Web服务在客户端拦截SOAP消息 [英] Intercept SOAP messages from and to a web service at the client

查看:117
本文介绍了从和Web服务在客户端拦截SOAP消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端与Web服务进行通信。我沟通类是通过Wsdl.exe用生成的C#类。我现在想记录所有传入和传出的消息。

I have a client that communicates with a web service. The class that I communicate with is a C# class that is generated through wsdl.exe. I now want to log all incoming and outgoing messages.

我到目前为止已经做的是写从自动生成的C#类继承的类,我已经覆盖了GetReaderForMessage方法。这样,我可以访问传入的消息或多或少是这样的:

What I've done so far is to write a class that inherits from the automatically generated C# Class and I have overridden the GetReaderForMessage method. That way I can access the incoming message more or less like this:

protected override XmlReader GetReaderForMessage(SoapClientMessage message, int bufferSize)
{
    System.Xml.XmlReader aReader = base.GetReaderForMessage(message, bufferSize);
    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    doc.Load(aReader);
    string content = doc.InnerXml.ToString();
    System.Xml.XmlReader aReader2 = System.Xml.XmlReader.Create(new System.IO.StringReader(content));

    return aReader2;
}

显然,我不是太满意这个解决方案,因为基本上我创建两个XML阅读器。一读取SOAP消息的内容和一个返回到方法调用者。另外,我真的不能做同样的GetWriterForMessage方法。

Obviously I'm not too happy with this solution, because basically I'm creating two xml readers. One to read the contents of the SOAP message and one to return to the method caller. Plus I can't really do the same with the GetWriterForMessage method.

不过,可能我只是在做的事情太难下手。难道例如可以直接读取SoapClientMessage对象的内容?我读过一些文章暗示我应该在这里使用SoapExtensions,但是从我能理解,如果客户是我创造本身就是一个Web服务,在这种情况下,它不是只会工作。

But may be I'm just doing things too difficult to start with. Is it for instance possible to read the contents of the SoapClientMessage object directly? I've read some articles suggesting that I should use SoapExtensions here, but from what I can understand, that would only work if the 'client' that I am creating is itself a web service which in this case it is not.

有什么建议?

推荐答案

我会建议寻找到使用的 SOAP扩展,这在我看来是非常适合这种情况。下面是描述过程中的几个环节。

I would suggest looking into using a SOAP extension, which in my opinion is ideal for this scenario. Here are a few links that describe the process.

http://msdn.microsoft.com/en-us/magazine/ cc164007.aspx

https://ebay.custhelp.com/cgi-bin/ebay.cfg/php/enduser/std_adp.php?p_faqid=350

HTTP://www.$c$cproject.com/KB/ Web服务/ efficientsoapextension.aspx

这篇关于从和Web服务在客户端拦截SOAP消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆