简体   繁体   English

从ASMX Web服务捕获原始XML(客户端)

[英]Capture Raw XML from ASMX Webservice (client)

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. 我有一个C#Winforms程序,该程序需要使用ASMX Web服务,因此需要从SOAP XML捕获请求/响应XML并将其存储到数据库中。

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. 我读了很多文章,建议使用SoapExtension来捕获XML,但据我所知,所有解决方案都不是线程安全的,它只是获取最后捕获的XML并假设它是一个。 。

For Example in below Link: 例如下面的链接:

http://blog.encoresystems.net/articles/how-to-capture-soap-envelopes-when-consuming-a-web-service.aspx 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. 要查看SOAP信封,只需在发布请求后立即访问TraceExtension.XmlRequest和TraceExtension.XmlResponse XmlDocument属性。

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? 有什么建议吗?

If you follow the suggestions in .Net Windows Form Client. 如果您遵循.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 : 从ASMX webservice捕获请求/响应SOAP ,但是将使用者配置为使用“服务引用”而不是“ Web引用”,则可以在app.config使用WCF跟踪:

    <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>

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. 如您所说,链接到的示例不起作用,因为它公开了静态xmlrequest和xmlresponse字段,可以在记录它们之前对其进行修改。 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. 但是,该示例确实演示了如何编写自己的SoapExtension(可能名为AuditSoapExtension或PersistSoapExtension),将这些信息保存到ProcessMessage方法中的数据库中。

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. 请注意,这对于每个请求来说都是很大的开销,如果您的负载将如您所建议的那样高,则可以考虑将持久性排队或批处理到实际数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM