tags:

views:

1271

answers:

3

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.

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.

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.

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.

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:

Implementing the SOAP Extension

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.

<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>

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

<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.

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

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

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

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).

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.

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?

+1  A: 

Chances are you want to get some rest.

You don't ever want to use WSE. WSE is obsolete.

You don't want to be using ASMX Web Services - Microsoft now considers them to be "legacy" technology, and will not be fixing bugs. BTW, WSE is based on ASMX, so what's that make it?


You only want to work with Windows Communication Foundation. The WCF Development Center on MSDN is at http://msdn.microsoft.com/wcf/.

Have fun, and stay away from the nasty, ancient, obsolete stuff.

John Saunders
I wish I could use wcf... It's a legacy (non .net) web service I'm connecting to, which uses a custom encryption scheme. This is why I'm trying to build the web service extension.
A: 

Yup - I was too tired.

I think the Web Service Extensions work with "Web references" (.net 2), not "Service references" (.net 3).

So I guess to alter my question - how do I intercept the request and response for a .net 3 "Service reference" connected to a legacy web service?

Now that I've changed the title, you'll get more attention. I've never used them, but I know there are message inspectors that you can use in WCF.
John Saunders
+3  A: 

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.

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.

Good luck! Z

Zach Bonham
Brilliant! Thank you for pointing me in the right direction - I now have access to both the request and response before the WCF client processes the soap body.Thank you all!
If it's the right direction, why not mark it as the answer? :)
Anderson Imes
marked as answer