0

I have a C# Winforms Program that need to consume an ASMX webservice, there is a requirement to capture the Request/Response XML from the SOAP XML and store into Database.

I've read up a lot article that suggest to use a SoapExtension to capture the XML, but as far for my understanding, all of the solutions isn't thread safe, it just simply grabbing the last captured XML and assume it is the one.

For Example in below Link:

http://blog.encoresystems.net/articles/how-to-capture-soap-envelopes-when-consuming-a-web-service.aspx

To view the SOAP envelopes, just access the TraceExtension.XmlRequest and TraceExtension.XmlResponse XmlDocument properties right after posting the request.

My program is expecting to have a lot of concurrent process running, the above solution will definitely work if the traffic is low, but my client is expecting a more decent solution that eliminate all the risk .

Any suggestion?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
PeirHwa.Soo
  • 79
  • 11

2 Answers2

1

If you follow the suggestions in .Net Windows Form Client. Capturing Request/Response SOAP from ASMX webservice, but configuring your consumer to use "Service References" rather than "Web References" you can use WCF tracing in your app.config:

    <system.diagnostics>
        <!-- add global listener: http://msdn.microsoft.com/en-us/library/b0ectfxd(v=vs.100).aspx -->
        <trace autoflush="true">
            <listeners>
                <add name="nlog" /> <!-- or whatever you registered in sharedListeners -->
            </listeners>
        </trace>
        <!-- nlog trace listeners: http://nlog-project.org/2010/09/02/routing-system-diagnostics-trace-and-system-diagnostics-tracesource-logs-through-nlog.html -->
        <sharedListeners>
            <add name="nlog" type="NLog.NLogTraceListener, NLog" />
            <add name="TraceFile" type="System.Diagnostics.TextWriterTraceListener"
              initializeData="trace.log"/>
        </sharedListeners>

        <!-- add SOAP listener: https://stackoverflow.com/questions/300674/getting-raw-soap-data-from-a-web-reference-client-running-in-asp-net -->
        <sources>
            <source name="System.Net" tracemode="protocolonly" maxdatasize="512000" switchValue="All">
                <listeners>
                    <add name="nlog"/>
                </listeners>
            </source>
            <!-- the others, like `System.Net.Sockets` and `System.ServiceModel` don't seem to do much -->
        </sources>
    </system.diagnostics>
Community
  • 1
  • 1
drzaus
  • 24,171
  • 16
  • 142
  • 201
0

As you said, the example linked to doesn't work because it exposes the static xmlrequest and xmlresponse fields which could be modified before you record it. However, the example does demonstrate how you could write your own SoapExtension possibly named AuditSoapExtension or PersistSoapExtension which would save the information to the database in the ProcessMessage method.

Beware that this is a lot of overhead for each request, you may look at queuing or batching the persistence to the actual database if your load is going to be as high as you suggest.

crad
  • 433
  • 3
  • 6
  • I need to obtain the XML in the process thread, in order store the XML together with other information. – PeirHwa.Soo Jan 03 '14 at 08:20
  • Look at the ProcessMessage method in the example. The SoapExtension is called on the same thread. That method is called for different stages in the message life cycle. You should be able to get an idea of what you need to do and then follow up if you need additional help with specifics. – crad Jan 03 '14 at 08:31
  • If you need to record other data in context as well, just add them as custom soap headers and have the extension do all the work. – crad Jan 03 '14 at 08:34