在WCF客户端拦截的邮件 [英] Intercept messages in a WCF Client

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

问题描述

有没有人得到了与Web服务扩展的经验吗?去过晚一天,并已在过去的几个小时抓我的头试图使从MS的例子Web服务扩展。

Has anyone got any experience with Web Service Extensions? Been a late day and have spent the past few hours scratching my head trying to make a web service extension from the MS examples.

我有一个.NET 3.5的Web服务客户端,通过向WSDL的引用生成,通过VS IDE项目>添加服务引用。这建立了我的Web服务客户端,所有工程确定。

I have an .net 3.5 web service client, built by adding a reference to the WSDL, via the VS IDE "Project > Add Service Reference". This built my web service client, and all works OK.

我需要拦截我的Web服务客户端的请求和响应主体。我发现很多到Web服务扩展的引用,但我有累的攻击,只是不能让我的扩展火。

I need to intercept the request and response body for my web service client. I have found lots of references to Web Service Extensions, but am having an attack of the tired, and just cant get my extensions to fire.

我使用了MS例如,从这里如何实现SOAP扩展(H TTP://msdn.microsoft.com/en-us/library/7w06t139.aspx),它建立在请求/响应流的记录

I've used the MS example from here "How to implement a SOAP extension" ( h ttp://msdn.microsoft.com/en-us/library/7w06t139.aspx) , which builds a logger for the request / response streams.

相关MS文章SOAP消息修改(的 http://msdn.microsoft.com/en-us/library/esw638yk(VS.85)的.aspx )展示了如何启用Web客户端的SOAP扩展:

The related MS article "Soap Message Modification" (http://msdn.microsoft.com/en-us/library/esw638yk(VS.85).aspx) shows how to enable the SOAP extension for the web client:

实现SOAP扩展

有两种方法运行客户机或服务器应用程序上的SOAP扩展。首先,您可以配置运行延期申请。要配置SOAP扩展为所有Web服务的所有Web方法,尤其是虚拟根运行,编辑Web.config文件中的元素部分。下面的代码显示该类型属性值必须在一行上,包括扩展的完全限定名,加上版本,区域性和签名的程序集的公钥标记。

There are two ways to run a SOAP extension on either a client or server application. First, you can configure the application to run the extension. To configure your SOAP extension to run for all Web methods on all Web services, especially a vroot, edit the Element section within the Web.config file. The following code shows that the type attribute value must be on one line and include the fully qualified name of the extension, plus the version, culture, and public key token of the signed assembly.

<结构>

<的System.Web>

< WEBSERVICES>

< soapExtensionTypes>

<加上TYPE =Contoso.MySoapExtension,版本= 2.0.0.0,文化=中性公钥= 31bf3856ad364e35
优先=1组=0/>

< / soapExtensionTypes>

< / WebServices的>

< /system.web>

< /结构>

<configuration>
<system.web>
<webServices>
<soapExtensionTypes>
<add type="Contoso.MySoapExtension, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="1" group="0"/>
</soapExtensionTypes>
</webServices>
</system.web>
</configuration>

我编译traceextension到自己的类库,并在Web服务的web.config文件中引用它项目像这样:

I've compiled the traceextension into its own class library, and referenced it in the web.config of the web service project like so:

<加上TYPE =TraceExtension,版本= 1.0.0.0,文化=中性公钥= ef8757fac167b8d8优先= 1组=高/>

<add type="TraceExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ef8757fac167b8d8" priority="1" group="High"/>

没有喜悦。没有记录,没有断点被命中。

No joy. Nothing is logged, no breakpoints are hit.

然后我删除所引用的类,并放弃了源代码转换成Web服务项目。

I then removed the referenced class, and dropped the source code into the web service project.

我想引用添加到它像这样(我的命名空间是ServcieTest001):

I tried to add a reference to it like so (my namespace is ServcieTest001):

<添加类型=ServiceTest001.TraceExtension组=高优先=1/>

<add type="ServiceTest001.TraceExtension" group="High" priority="1" />

我用下面的线为指导为使我延伸越来越-RAW皂数据 - 从-A-Web的参考客户磨合-ASP-网(H TTP://stackoverflow.com/questions/300674/getting-raw-肥皂数据从-A-Web的参考客户磨合-ASP网)。

I used the following thread as a guide as to enabling me extension "getting-raw-soap-data-from-a-web-reference-client-running-in-asp-net" (h ttp://stackoverflow.com/questions/300674/getting-raw-soap-data-from-a-web-reference-client-running-in-asp-net).

仍然没有喜悦。然后我复制从上面的线程的代码,当我提出一个SOAP请求仍然无法扩展到火。

Still no joy. I then copied the code from the above thread, and still cannot get the extension to fire when I make a SOAP request.

任何人都可以用一些三分球帮助吗?我必须失去了一些东西真的很傻!任何人都可以点我到正常运行的可下载的Web服务扩展演示项目,这样我就可以拆开它,并制定出我错过了什么?

Can anyone help with some pointers? I must be missing something really silly! Can anyone point me to a functioning downloadable web service extension demo project, so I can disassemble it and work out what I'm missing?

推荐答案

约翰是正确的,你可以使用实现IClientMessageInspector自定义客户端行为在客户机上截获的消息。见如何:检查或修改在MSDN上的客户端消息

John is right, you can intercept the messages on the client using a custom client behavior that implements IClientMessageInspector. See How To: Inspect or Modify Messages on the Client on MSDN.

唯一'棘手'一下的是,如果你打算修改消息的体内的,那么你将需要创建原件及复印件消息第一。请参见使用Message类了解糊糊的细节。

The only thing 'tricky' about it is that if you plan on modifying the message body then you will need to create a copy of the original message first. See Using the Message Class for the gooey details.

这篇关于在WCF客户端拦截的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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