2012-02-02 69 views
2

我有一个将数据发送到Web服务并将数据存储到XML文件的程序。我想知道是否有一个类或一个方法可以捕获到达服务的soap对象并将其转储到文本文件。谁能告诉我如何做到这一点?将SOAP作为文本转储到文件

编辑1:

确定,所以通过张贴在评论的话题会后,我编辑我的web.config文件看起来像这样:

<?xml version="1.0"?> 
<configuration> 

<configSections> 
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
     <section name="XML_New.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </sectionGroup> 
</configSections> 
<appSettings> 
<add key="username" value="admin"/> 
<add key="password" value="admin"/> 
</appSettings> 
<connectionStrings/> 
<system.diagnostics> 
<sources> 
    <source name="System.ServiceModel.MessageLogging"> 
    <listeners> 
     <add name="messages" 
     type="System.Diagnostics.XmlWriterTraceListener" 
     initializeData="c:\logs\messages.svclog" /> 
    </listeners> 
    </source> 
</sources> 
</system.diagnostics> 

<system.serviceModel> 
<diagnostics> 
    <messageLogging logEntireMessage="true" 
logMalformedMessages="true" 
logMessagesAtServiceLevel="true" 
logMessagesAtTransportLevel="true" 
maxMessagesToLog="420"> 
    <filters> 
     <add nodeQuota="10" 
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> 

/soap:Envelope/soap:Header 
     </add> 
    </filters> 
    </messageLogging> 
</diagnostics> 
</system.serviceModel> 
<system.web> 
    <compilation debug="true" > 

    </compilation> 
<authentication mode="Forms" /> 
</system.web> 
<applicationSettings> 
    <XML_New.Properties.Settings> 
     <setting name="XML_New_localhost_Service1" serializeAs="String"> 
      <value>http://localhost:1689/Admin.asmx</value> 
     </setting> 
    </XML_New.Properties.Settings> 
</applicationSettings> 
</configuration> 

的文件应该被记录到c:\ logs \ messages.svclog,但由于soeme的原因它没有。任何人有一个想法为什么?

+0

没有什么,我不知道是否有从通过Wireshark的观看繁忙的交通分开的方法。 – 2012-02-02 22:12:07

+0

[C#SOAP Web服务客户端 - 显示如何记录所有原始SOAP输入和输出的示例的可能的重复?](http://stackoverflow.com/questions/566855/c-sharp-soap-web-services-client-例如,显示如何登录所有原料肥皂中) – 2012-02-02 22:14:10

+0

@MK谢谢你看看int这个和病后的aditional问题是我有。 – 2012-02-02 22:30:50

回答

4

在asmx服务级别,您可以使用soap扩展。文档和工作示例:http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapextension.aspx。您可以复制粘贴整个事物,更改GetInitializer中的转储路径,它可能只适用于您。 +1

+0

实际上,这显然可以在客户端插入(基于.net/soap的)。我自己并不知道。我多次在asmx上做过这个;奇迹般有效。 – 2012-02-03 14:33:31