View raw XML request
I am very new to WCF and SOAP messaging but I have managed to put together a reasonably good client which I am using to download news stories from a media organisation. I have generated proxy classes which obviously abstract a lot away and mean that I am basically just creating objects, calling methods and iterating through resul开发者_如何学Pythonts.
My issue is that I have raw XML examples of what the calls to the web service should look like and I want to be able to "compare" these to the calls that I am making. Basically I need to ensure that the calls that I am making are the same as the example XML files for testing purposes.
Does what I am asking make sense or am I going about this the wrong way? Please let me know if there is any necessary information that I have left out, I could bang on for paragraphs but am not sure what information is relevant.
You can use WCF tracing to log the raw XML messages. The following is .config
enables WCF tracing with raw message logging:
<configuration>
<system.serviceModel>
<diagnostics>
<messageLogging maxMessagesToLog="30000"
logEntireMessage="true"
logMessagesAtServiceLevel="true"
logMalformedMessages="true"
logMessagesAtTransportLevel="true">
</messageLogging>
</diagnostics>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.IdentityModel" switchValue="Verbose" logKnownPii="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<!-- Log all messages in the 'Messages' tab of SvcTraceViewer. -->
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml" />
</listeners>
</source>
<!-- ActivityTracing and propogateActivity are used to flesh out the 'Activities' tab in
SvcTraceViewer to aid debugging. -->
<source name="System.ServiceModel" switchValue="Error, ActivityTracing" propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<!-- This records Microsoft.IdentityModel generated traces, including exceptions thrown
from the framework. -->
<source name="Microsoft.IdentityModel" switchValue="Warning">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="trace.e2e" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
</configuration>
You can read more about WCF Tracing from MSDN: Configuring Tracing.
Microsoft provides a Service Trace Viewer Tool to read .svclog files.
Make sure the path defined in initializeData
is writable by your service.
Have you used the Service Trace Viewer tool from Microsoft? This MSDN page will give you the details on how to use it.
The stock answer for this is to use fiddler as a proxy - this will allow you to view the outgoing and incoming messages between your client and the service.
Can't yet speak from personal experience, however team members developing for me (in a former life) have - quite rightly - coded up our service wrappers with built in support for use of a proxy explicitly to simplify use of fiddler.
You can create your own message inspector using the IClientMessageInspector interface and get the raw messages for both the request and response.
Here's a good post on how to do it ==> http://www.keithelder.net/blog/archive/2008/01/15/How-to-Get-Around-WCFs-Lack-of-a-Preview-Web.aspx
I don't know much about WCF, but you could redirect your connection to a different web server on your network that logged the body somewhere. This would allow you to see exactly what you are sending, but would require some infrastructure work. This could be a web server running on your development machine.
精彩评论