[英]How Can I Log Exactly The Messages Sent and Received From a WCF Client
Please do not answer using the WCF Trace tool unless give explicit instructions on how to capture the actual message including headers and faults. 请不要使用WCF跟踪工具回答,除非提供有关如何捕获实际消息(包括标头和错误)的明确说明。 This link does not work.
此链接不起作用。
Also, do not answer IClientMessageInspector
unless you know how to get it to include all headers ( which it doesn't ) and capture responses that have fault elements that don't parse. 此外,不要回答
IClientMessageInspector
除非您知道如何让它包含所有标题( 它不包含)并捕获具有不解析的错误元素的响应。
With pre-wcf web services, you could write a SoapExtension
that worked flawlessly. 使用pre-wcf Web服务,您可以编写一个完美运行的
SoapExtension
。
write a custom message encoder . 编写自定义消息编码器 。 it has access to all headers.
它可以访问所有标题。 deoending on how generic you want your solution to be you may need to write it such that it gets in the ctor the real encoder.
关于你希望你的解决方案如何通用的deoending你可能需要写它,以便它在真正的编码器中。
just a few days ago I implemented a "Wrapper encoder" in this thread . 就在几天前,我在这个帖子中实现了一个“Wrapper编码器”。 that encoder changed the message.
那个编码器改变了消息。 you don't need to do this, you can just log it and pass it to the transport as I also did.
您不需要这样做,您可以记录它并将其传递给传输,就像我一样。
A class implementing IEndpointBehavior allows you to trap and log inbound/outbound messages. 实现IEndpointBehavior的类允许您捕获和记录入站/出站消息。
See an example here http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applydispatchbehavior.aspx 请参阅此处的示例http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applydispatchbehavior.aspx
You'll also need a class implementing IDispatchMessageInspector 您还需要一个实现IDispatchMessageInspector的类
I found this as well: 我也发现了这个 :
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="messages"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\log\wcfMessages.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="1000000"
maxSizeOfMessageToLog="10000000"/>
</diagnostics>
</system.serviceModel>
It's not ideal since you have to use a tool to view the messages but it does seem to capture the actual messages with all headers and faults, etc. 它不是理想的,因为您必须使用工具来查看消息,但它似乎捕获了包含所有标题和错误的实际消息等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.