简体   繁体   English

如何正确记录从WCF客户端发送和接收的消息

[英]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.

相关问题 SignalR:客户端未收到在集线器外部发送的消息 - SignalR: Messages sent outside hub are not received on client 如何从客户端桌面应用程序记录和检索错误消息? - How can I log and retrieve error messages from a client-side desktop app? 如何加密但不保护WCF消息? - How can I encrypt, but not secure WCF messages? 如何在WCF Web服务上捕获肥皂消息? - How can I catch soap messages on WCF Web Service? 如何使用WCF在事务性MSMQ中明确标记消息中毒 - How can I explicitly mark messages as poisoned in a transactional MSMQ with WCF 我如何保护从客户端发送到服务器的流量从中间工具中的人? - How can i protect the traffic sent from client to server from Man in the middle tools? 在使用客户端的频道之前,如何检查WCF主机是否可用? - How can I check that a WCF host is available before I use a channel from a client? WCF 4 REST-如何完全控制发送的消息 - WCF 4 REST - How to gain full control over the messages sent 我正在使用WCF服务,该服务需要来自.NET 2网站的标头。 如何以编程方式将标头添加到邮件中? - I am consuming a WCF service that requires headers from a .NET 2 website. How can I programmatically add the headers to the messages? 如何使用WCF调用从客户端Windows Phone 8.0 Silverlight返回对象的方法 - How can I call a method that returns an object from a client windows phone 8.0 silverlight using WCF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM