我使用以下方法调用Web服务:
ServiceReference1.TestClient svc = new ServiceReference1.TestClient("TestBinding");
svc.ClientCredentials.UserName.UserName = "User1";
svc.ClientCredentials.UserName.Password = "Pwd1";
ServiceReference1.GenerateIDRequest rq = new ServiceReference1.GenerateIDRequest();
var response = svc.GenerateID(rq);
我想要做的是获取发送到Web服务的请求的原始xml,包括标题。
我将以下部分添加到我的App.config文件中:
<system.diagnostics>
<trace autoflush="true"/>
<sources>
<source name="System.Net">
<listeners>
<add name="TraceFile"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="TraceFile"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="TraceFile" type="System.Diagnostics.TextWriterTraceListener"
initializeData="trace.log"/>
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose"/>
<add name="System.Net.Sockets" value="Verbose"/>
</switches>
</system.diagnostics>
现在我在bin文件夹中生成了trace.log
个文件。唯一的问题是请求xml有以下格式:
System.Net Verbose: 0 : [14476] 00000000 : 3C 73 3A 45 6E 76 65 6C-6F 70 65 20 78 6D 6C 6E : <s:Envelope xmln
System.Net Verbose: 0 : [14476] 00000010 : 73 3A 73 3D 22 68 74 74-70 3A 2F 2F 73 63 68 65 : s:s="http://sche
System.Net Verbose: 0 : [14476] 00000020 : 6D 61 73 2E 78 6D 6C 73-6F 61 70 2E 6F 72 67 2F : mas.xmlsoap.org/
System.Net Verbose: 0 : [14476] 00000030 : 73 6F 61 70 2F 65 6E 76-65 6C 6F 70 65 2F 22 3E : soap/envelope/">
System.Net Verbose: 0 : [14476] 00000040 : 3C 73 3A 42 6F 64 79 20-78 6D 6C 6E 73 3A 78 73 : <s:Body xmlns:xs
System.Net Verbose: 0 : [14476] 00000050 : 69 3D 22 68 74 74 70 3A-2F 2F 77 77 77 2E 77 33 : i="http://www.w3
System.Net Verbose: 0 : [14476] 00000060 : 2E 6F 72 67 2F 32 30 30-31 2F 58 4D 4C 53 63 68 : .org/2001/XMLSch
System.Net Verbose: 0 : [14476] 00000070 : 65 6D 61 2D 69 6E 73 74-61 6E 63 65 22 20 78 6D : ema-instance" xm
System.Net Verbose: 0 : [14476] 00000080 : 6C 6E 73 3A 78 73 64 3D-22 68 74 74 70 3A 2F 2F : lns:xsd="http://
System.Net Verbose: 0 : [14476] 00000090 : 77 77 77 2E 77 33 2E 6F-72 67 2F 32 30 30 31 2F : www.w3.org/2001/
System.Net Verbose: 0 : [14476] 000000A0 : 58 4D 4C 53 63 68 65 6D-61 22 3E 3C 43 72 65 61 : XMLSchema">
如何在不必编辑trace.log
文件的情况下获取纯原始xml?
答案 0 :(得分:0)
我使用它(在<system.serviceModel>
内):
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true"
logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
maxMessagesToLog="300" />
<endToEndTracing propagateActivity="true" activityTracing="true"
messageFlowTracing="true" />
</diagnostics>
和此(<system.serviceModel>
之后):
<system.diagnostics>
<sources>
<source propagateActivity="true" name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelTraceListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose,ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="c:\temp\messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="c:\temp\tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
您可以在switchValue
您可以使用 Microsoft Service Trace Viewer 检查原始邮件。