views:

132

answers:

4

Is there a way to get raw XML which is generated by SOAP request in .net. I don't know how to ask this precisely, but here goes

I add web reference and call some method. Is there a way to know what XML is being sent. For debugging purposes only, so quick and dirty way is enough

P.S. SSL is used, so snipping doesn't help here

A: 

You can try: http://www.pocketsoap.com/tcpTrace/.

+3  A: 

I typically do this sort of thing with Fiddler.

Stick this in the config file:-

<system.net>
 <defaultProxy enabled="true">
  <proxy proxyaddress="http://127.0.0.1:8888" bypassonlocal="False"/>
 </defaultProxy>
</system.net>

Fire up fiddler and you should be able to monitor all http traffic coming from your application. Just set enabled to false before closing fiddler.

AnthonyWJones
+2  A: 

the easiest way to get any data sent across the network is to install wireshark and snoop on the raw data as it passes through the network stack. The benefit is that you really see what's being sent, before any other application or service gets to modify it. There are plenty of examples and blogs on the web.

You can also use it to replay soap requests. Its great for other networking too - not just SOAP, but normal HTTP and TCP, and even serial comms.

gbjbaanb
+1  A: 

You can create a SoapExtensionAttribute and apply it to your web service methods.

Create a class that is derived from SoapExtensionAttribute.

Create another class that derives from SoapExtension.

The Type of your SoapExtensionAttribute should be the type of your SoapExtension.

Once you're in the SoapExtension, you have access to the moment where the data has been serialize/deserialized.

Here are the 4 specific stage:

SoapMessageStage.BeforeSerialize
SoapMessageStage.AfterSerialize           *
SoapMessageStage.BeforeDeserialize        *
SoapMessageStage.AfterDeserialize

The ones with the '*' are the stages where you want to access the stream. From there, you can log the xml that gets in and out of you web service.

That's what we do here, it works perfectly.

Here's a link that explains more in details: http://progtutorials.tripod.com/soapext.htm

Hope that have been of some help.

Jean-Francois
Have you seen the stream returned from SoapMessage being write only? I'm trying your suggestion and will be back with results soon
Sergej Andrejev
Yeah, the trick is to copy the stream in a memory stream inside your SoapExtension.
Jean-Francois