David Chappelle
David Chappelle

Reputation: 1243

In C#, how would I capture the SOAP used in a web service call?

I have a C# application that is a client to a web service. One of my requirements is to allow capturing the SOAP that I send, so that if there is a problem, I can either fix the bug, or demonstrate that the problem is in the service I am calling.

My WebReference proxy service class derives from System.Web.Services.Protocols.SoapHttpClientProtocol as usual. If I had a magic wand, I would make this base class implement an event OnPost that I could handle to write the SOAP into my logs and continue.

Short of running a packet sniffer like WireShark, is there an easy way to get this level of logging?

Upvotes: 16

Views: 71650

Answers (6)

bnieland
bnieland

Reputation: 6496

To see this traffic in fiddler use the following code:

mySoapHttpClientProtocol.Url = mySoapHttpClientProtocol.Url.Replace("localhost", "localhost.fiddler");

Otherwise, Visual Studio's built in web server will bypass all proxies.

Upvotes: 2

Zachary Yates
Zachary Yates

Reputation: 13386

I think what you are looking for is addressed in this question:

Getting RAW Soap Data from a Web Reference Client running in ASP.net

It looks like a lot of code though.

Upvotes: 15

uzay95
uzay95

Reputation: 16632

Just "." add the address in your endpoint after "localhost". like this:

      <endpoint address="http://localhost.:8868/FEInvoice.asmx" binding="basicHttpBinding"
    bindingConfiguration="FEInvoice_Test" contract="EInvoiceIntegration.FEInvoiceSoap"
    name="FEInvoice_Test" />

Upvotes: 0

Rob Kent
Rob Kent

Reputation: 5193

For some reason Fiddler was not showing my local service calls when using the ASP.NET Development Server that comes with Visual Studio. To get around this I changed the web service Url at runtime to be the Fiddler port, just to capture the SOAP message.

You can do this from the Immediate window, for example:

myservice.Url = "localhost:8888" (or whatever port you have Fiddler on)

I used the SoapUI client to test responses.

Upvotes: 0

Moose
Moose

Reputation: 5412

If the application is running on your local box and the web service isn't doing anything funky, you can use Fiddler. Fire Up IE, run Fiddler, and you'll see your web service calls go through fiddler's proxy too.

I just used this this morning to do almost the same thing. I had to prove the data my web service was sending wasn't messed up.

Upvotes: 4

FlySwat
FlySwat

Reputation: 175603

Take a look at SoapExtensions.

They are what you need.

Upvotes: 1

Related Questions