Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check what xml is sent during web service request?

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

like image 305
Sergej Andrejev Avatar asked Jan 23 '23 17:01

Sergej Andrejev


2 Answers

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.

like image 141
AnthonyWJones Avatar answered Jan 26 '23 05:01

AnthonyWJones


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.

like image 43
Jean-Francois Avatar answered Jan 26 '23 07:01

Jean-Francois