views:

785

answers:

3

I'm writing UI to test an asmx web service. Server and client are .NET. Client proxy has been generated using wsdl.exe.

I would like to intercept and store a string representation of outgoing and incoming SOAP messages generated as a result of calling methods on the web proxy, so I can add a feature to the UI which will show the message just sent/received.

I dimly recall there are two pairs of extension points where code can can be added to intecept the message but I cannot remember how this was done. I think the examples I have in mind involved compressing some part of the message on the client and the reverse on the server, even though in my scenario, I want to store rather than alter the message.

Any hints and help gratefully received.

(I've partially implemented a SoapExtension. I don't understand how the ChainStream method works, and I'm not sure how to notify a listener that a soap message has been trapped (since I'm not in control of instantiating the soap extension).'

A: 

I would suggest 2 tricks :

  • subclassing the proxy and overloading your methods (a little bit boring but you can generate code like in this project : http://ftwsf.codeplex.com/)
  • using Async signatures and subcribe to 'Completed' events of each methods (you can do this by reflection to avoid writting to much code)

If you need more info about these tricks, just let me know.

Manitra Andriamitondra
+1  A: 

You're on the right track with SoapExtension. Did you see the documentation and example here? http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapextension.aspx

The idea with ChainStream is you get passed the network stream that the request would be written to, and you have the option of returning a different stream. So if you want to save a copy of the request, return a MemoryStream, which the web services client will write the request into, and then in the ProcessMessage call you can copy the data out of there and pass it to your UI.

alexdej
Thanks, I based my solution on the MSDN example. I created a static class encapsulating a dictionary to store the outbound and inbound messages which my UI subsequently reads.
IanT8
A: 

You'd really be better off using WCF as your client technology. You could then simply use WCF message-level tracing to log the incoming and outgoing messages. This is done simply through configuration.

There's no reason you have to use an ASMX client just because you are using an ASMX service.

John Saunders