简体   繁体   中英

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?

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.

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.

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.

Take a look at SoapExtensions .

They are what you need.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM