开发者

Extract SOAP messages form svclog

开发者 https://www.devze.com 2023-01-28 03:46 出处:网络
Extract SOAP messages form svclog Hi guys! I enabled trace listening in my app to trace soap messages. Take a look at this: http://msdn.microsoft.com/en-us/library/ms732023.aspx

Extract SOAP messages form svclog

Hi guys!

I enabled trace listening in my app to trace soap messages.

Take a look at this: http://msdn.microsoft.com/en-us/library/ms732023.aspx

My app is a client to a web .net service.

So now I can collect infos in a svclog, well!

But how can I extract soap messages from this? In the log soap messages were written in this form:

...

System.Net Verbose: 0 : [5344] Data from ConnectStream#53182860::Write

System.Net Verbose: 0 : [5344] 00000000 : 3C 3F 78 6D 6C 20 76 65-72 73 69 6F 6E 3D 22 31 : System.Net Verbose: 0 : [5344] 00000010 : 2E 30 22 20 65 6E 63 6F-64 69 6E 67 3D 22 75 74 : .0" encoding="ut

System.Net Verbose: 0 : [5344] 00000020 : 66 2D 38 22 3F 3E 3C 73-6F 61 70 3A 45 6E 76 65 : f-8"?> System.Net Verbose: 0 : [5344] 00000030 : 6C 6F 70 65 20 78 6D 6C-6E 73 3A 73 6F 61 70 3D : lope xmlns:soap=

System.Net Verbose: 0 : [5344] 00000040 : 22 68 74 74 70 3A 2F 2F-73 63 68 65 6D 61 73 2E : "http://schemas.

System.Net Verbose: 0 : [5344] 00000050 : 78 6D 6C 73 6F 61 70 2E-6F 72 67 2F 73 6F 61 70 : xmlsoap.org/soap

System.Net Verbose: 0 : [5344] 00000060 : 2F 65 6E 76 65 6C 6F 70-65 2F 22 20 78 6D 6C 6E : /envelope/" xmln

System.Net Verbose: 0 : [5344] 00000070 : 73 3A 73 6F 61 70 65 6E-63 3D 22 68 74 74 70 3A : s:soapenc="http:

System.Net Verbose: 0 : [5344] 00000080 : 2F 2F 73 63 68 65 6D 61-73 2E 78 6D 6C 73 6F 61 : //schemas.xmlsoa

System.Net Verbose: 0 : [5344] 00000090 : 70 2E 6F 72 67 2F 73 6F-61 70 2F 65 6E 63 6F 64 : p.or开发者_运维百科g/soap/encod

System.Net Verbose: 0 : [5344] 000000A0 : 69 6E 67 2F 22 20 78 6D-6C 6E 73 3A 74 6E 73 3D : ing/" xmlns:tns=

...

There's a way to extract them from svclog file?

I cannot modify the code, so the configuration way to trace this stuff is my preferred solution.

Thank you!

Nando


<?xmlversion="1.0" encoding="utf-8" ?>
  <configuration>
    <system.web>
      <webServices>
        <soapExtensionTypes>
          <add 
               type="MySoapExtensionLib.MyExtension, MySoapExtensionLib"
               priority="1"
               group="High" />
        </soapExtensionTypes>
      </webServices>
    </system.web>
  </configuration>here

For my needs:

  1. Don't want to touch existing code
  2. Cannot use WCF (using .NET 2.0)

the best way to log SoapMessages is to create a spare SoapExceptionLib class library project with a custom SoapException. If you write your own SoapException (in this example we have MyExtension declared in MySoapExtensionLib library project), you can enable it all over your project (so for all web services calls you will do) using configuration. If you want only some web service calls to use your extension, you should use attributes.

See this project in CodeProject to have a working example:
http://www.codeproject.com/KB/webservices/Soap_Extension_Progress.aspx
Hope this helps.
Bye,
Nando


If this is a client created with "Add Service Reference", then you can configure message tracing. This will show you the messages in XML.


I used this piece of code some moths ago, but I cannot remember where I found it. It do the trick, after all, but is not an elegant solution.

Bye, Nando

        ...

    //call the web service method
    var myResponseData = ws.CallMyWebServiceMethod(myRequestData)
    //call this method just after the web servcice method call, or it will not work!
    DiagnoseResponseProblem();
    ...


    private void DiagnoseResponseProblem()
    {
        HttpContext hc = HttpContext.Current;
        string SoapResponse = null;
        string SoapRequest = null;

        // Post processing debugging pull out the actual soap message and debug it.
        if (hc != null)
        {
            SoapRequest = hc.Items["SOAPRequest"].ToString();
            SoapResponse = hc.Items["SOAPResponse"].ToString();
        }
        else
        {
            try
            {
                SoapResponse = System.Runtime.Remoting.Messaging.CallContext.GetData("SOAPResponse").ToString();
                SoapRequest = System.Runtime.Remoting.Messaging.CallContext.GetData("SOAPRequest").ToString();
                System.Runtime.Remoting.Messaging.CallContext.FreeNamedDataSlot("SOAPResponse");
                System.Runtime.Remoting.Messaging.CallContext.FreeNamedDataSlot("SOAPRequest");

                //NANDO: saving SOAP messages
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(SoapRequest);
                xmlDoc.Save(@"C:\temp\soap-request.xml");
                xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(SoapResponse);
                xmlDoc.Save(@"C:\temp\soap-response.xml");
            }
            // Ignore...most likely this system does not 
            // have the remote message context setup.
            catch (Exception ex)
            {
                //...
            }
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消