.net 从svclog中提取SOAP消息 从svclog中提取SOAP消息

.net 从svclog中提取SOAP消息 从svclog中提取SOAP消息,.net,logging,soap,trace,.net,Logging,Soap,Trace,嗨,伙计们 我在应用程序中启用了跟踪侦听以跟踪soap消息。 看看这个: 我的应用程序是web.net服务的客户端。 现在我可以在svclog中收集信息了 但是如何从中提取soap消息呢? 在日志中,soap消息以以下形式写入: … System.Net详细信息:0:[5344]来自ConnectStream的数据#53182860::Write System.Net详细信息:0:[5344]00000000:3C 3F 78 6D 6C 20 76 65-72 73 69 6F 6E 3D 2

嗨,伙计们

我在应用程序中启用了跟踪侦听以跟踪soap消息。
看看这个:

我的应用程序是web.net服务的客户端。
现在我可以在svclog中收集信息了

但是如何从中提取soap消息呢? 在日志中,soap消息以以下形式写入:

System.Net详细信息:0:[5344]来自ConnectStream的数据#53182860::Write
System.Net详细信息:0:[5344]00000000:3C 3F 78 6D 6C 20 76 65-72 73 69 6F 6E 3D 22 31: System.Net详细信息:0:[5344]00000010:2E 30 22 20 65 6E 63 6F-64 69 6E 67 3D 22 75 74:.0“encoding=“ut
System.Net详细信息:0:[5344]00000020:66 2D 38 22 3F 3E 3C 73-6F 61 70 3A 45 6E 76 65:f-8“> System.Net详细信息:0:[5344]00000030:6C 6F 70 65 20 78 6D 6C-6E 73 3A 73 6F 61 70 3D:lope xmlns:soap=
System.Net详细信息:0:[5344]00000040:22 68 74 70 3A 2F 2F-73 63 68 65 6D 61 73 2E:“http://schemas.
System.Net详细信息:0:[5344]00000050:78 6D 6C 73 6F 61 70 2E-6F 72 67 2F 73 6F 61 70:xmlsoap.org/soap
System.Net详细信息:0:[5344]00000060:2F 65 6E 76 65 6C 6F 70-65 2F 22 20 78 6D 6C 6E:/envelope/“xmln
System.Net详细信息:0:[5344]00000070:73 3A 73 6F 61 70 65 6E-63 3D 22 68 74 70 3A:s:soapenc=“http:
System.Net详细信息:0:[5344]00000080:2F 2F 73 63 68 65 6D 61-73 2E 78 6D 6C 73 6F 61://schemas.xmlsoa
System.Net详细信息:0:[5344]00000090:70 2E 6F 72 67 2F 73 6F-61 70 2F 65 6E 63 6F 64:p.org/soap/encod
System.Net详细信息:0:[5344]000000 A0:69 6E 67 2F 22 20 78 6D-6C 6E 73 3A 74 6E 73 3D:ing/“xmlns:tns=

有办法从svclog文件中提取它们吗?
无法修改代码,因此跟踪这些内容的配置方式是我首选的解决方案

谢谢!

Nando

如果这是使用“添加服务引用”创建的客户端,则可以进行配置。这将以XML格式显示消息。

如果这是使用“添加服务引用”创建的客户端,然后您可以配置。这将以XML格式显示消息。

几天前我使用了这段代码,但我记不起在哪里找到的。 毕竟,它确实起到了作用,但并不是一个优雅的解决方案

再见,南多

        ...

    //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)
            {
                //...
            }
        }
    }

几个月前我用过这段代码,但我不记得在哪里找到的。 毕竟,它确实起到了作用,但并不是一个优雅的解决方案

再见,南多

        ...

    //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)
            {
                //...
            }
        }
    }


希望这有帮助。
再见,
南多



希望这有帮助。
再见,

南多是的。我在配置中启用了跟踪,结果得到了一个*.svclog文件,这是一个常见的xml文件。但我无法从中提取SOAP消息。你知道我可以用什么方法吗?非常感谢。您正在谈论服务跟踪查看器工具(SvcTraceViewer.exe)?我使用了它,但它也不能提取普通的soap消息-(我说的是配置消息跟踪。请阅读本文及其子文章。然后,您可以使用该工具查看消息跟踪,也可以直接使用XML(.svclog文件是XML)是的,但我无法提取普通SOAP消息;它们是成批报告的,您是否尝试过查看一个svclog?顺便说一句,谢谢您的兴趣!您错了。请配置消息日志记录,如中所示。将其配置为记录整个消息。您将希望在执行此操作时关闭加密。您将找到整个SOAP消息是的,是的。我在配置中启用了跟踪,结果得到了一个*.svclog文件,这是一个普通的xml。但是我无法从中提取SOAP消息。你知道我可以使用的方法吗?谢谢!你说的是服务跟踪查看器工具(SvcTraceViewer.exe)?我使用了它,但它也不能提取普通soap消息。:-(我说的是配置消息跟踪。请阅读本文及其子文章。然后,您可以使用该工具查看消息跟踪,也可以直接使用XML(.svclog文件是XML)是的,但我无法提取普通SOAP消息;它们是成批报告的,您是否尝试过查看一个svclog?顺便说一句,谢谢您的兴趣!您错了。请配置消息日志记录,如中所示。将其配置为记录整个消息。您将希望在执行此操作时关闭加密。您将找到整个SOAP消息
MessageLogTraceRecord
下的sage。