问题
I have added a wsdl file in my project as a service reference. The application sends SOAP messages to a particular device which then sends the response in SOAP format.
Is there a way to look at the actual SOAP message that is wrapped in XML? Having to turn on wireshark to look at the SOAP messages gets tedious.
回答1:
You are probably looking for SOAP extension, look at this post:
Get SOAP Message before sending it to the WebService in .NET
回答2:
Use Fiddler to inspect the messages. Ref: Using fiddler.
回答3:
You can use the SVCTraceViewer to trace what are the messages that are being sent to and fro for each service call. You just have to set up the config and WCF builds the log files with the .svclog extension.
More details on this tool and its associated configuration is here. This does not require any 3rd party tool or network inspectors to be run etc... This is out of the box from Microsoft.
回答4:
In case of WCF it has a less-known way to intercept original XML - custom MessageEncoder. It works on low level, so it captures real byte content including any malformed xml.
If you want use this approach you need to wrap a standard textMessageEncoding with custom message encoder as new binding element and apply that custom binding to endpoint in your config.
Also there is an example how I did it in my project - wrapping textMessageEncoding, logging encoder, custom binding element and config.
来源:https://stackoverflow.com/questions/16757990/how-to-look-at-the-actual-soap-request-response-in-c-sharp