[英]WCF REST client with TransferMode=Streamed - logging entire (“raw”) http requests/responses
This is on .Net 4, full framework. 这是在.Net 4完整框架上。
I'm trying to make a simple winforms app that will make some simple WCF REST calls. 我正在尝试制作一个简单的winforms应用程序,该应用程序将进行一些简单的WCF REST调用。 It's using ChannelFactory and the service contract interface.
它使用ChannelFactory和服务协定接口。 Of the ~20 methods in the interface, 2 of them involve Stream (an upload and a download method) so the service side (and currently also the client side) using TransferMode=Streamed.
接口中的约20种方法中,有2种涉及Stream(上载和下载方法),因此服务端(当前还包括客户端)使用TransferMode = Streamed。
My goal is to include the full HTTP request and response (much like you would see in ethereal/wireshark, or fiddler, or whatever), with headers, in a textbox of the winforms app (just to show what went over the wire) 我的目标是在Winforms应用程序的文本框中包含完整的HTTP请求和响应(就像您在ethereal / wireshark,fiddler或其他东西中看到的一样)和标头(仅显示通过网络传输的内容)
In trying to use the built-in diagnostics (via SvcConfigEditor) and my own (via implementing IClientMessageInspector and then IEndpointBehavior to add the inspector, then channelFactory.Endpoint.Behaviors.Add to add the behavior :), I'm having 2 issues: 在尝试使用内置诊断程序(通过SvcConfigEditor)和我自己的诊断程序(通过实现IClientMessageInspector然后通过IEndpointBehavior添加检查器,然后使用channelFactory.Endpoint.Behaviors.Add添加行为:)时,我遇到了两个问题:
One fallback would be to move the client to Buffered and just change to StreamedRequest for the one upload call and StreamedResponse for the download call (but I'd have to do that programmatically AFAICT, as it's set at the binding level in the config and I don't see anyway of doing it via attributes on the calls), which would take care of the 'body' part and leave me with just the "get the http request headers" (issue #1, specifically request.Properties["httpRequest"].Headers being empty) to deal with, but I'm hoping there's some way of logging the 'raw' messages without doing so, leaving the TransferMode as Streamed. 一个后备方法是将客户端移动到Buffered,然后将一个上载调用更改为StreamedRequest,将一个下载调用更改为StreamedResponse(但我必须以编程方式执行AFAICT,因为它是在config和我的绑定级别中设置的无论如何都看不到通过调用的属性来执行此操作),这会处理“正文”部分,只剩下“获取http请求标头”(问题1,特别是request.Properties [“ httpRequest] “]。标头为空)来处理,但我希望有一些方法可以记录“原始”消息,而无需这样做,而将TransferMode保留为Streamed。
Thanks! 谢谢!
I can't find any reference right now, but it's a known fact that you cannot capture the contents of a streamed message to WCF tracing. 我现在找不到任何参考,但这是众所周知的事实,您无法捕获到WCF跟踪的流式消息的内容。 When streaming is enabled, only the headers of the message will be traced.
启用流传输后,将仅跟踪邮件的标头。
Here's the source: Configuring Message Logging on MSDN 这是源:在MSDN上配置消息记录
See towards the end of the page: 参见页面末尾:
Service Level
服务级别
Messages logged at this layer are about to enter (on receiving) or leave (on sending) user code.
在此层记录的消息即将输入(接收)或离开(发送)用户代码。 If filters have been defined, only messages that match the filters are logged.
如果定义了过滤器,则仅记录与过滤器匹配的消息。 Otherwise, all messages at the service level are logged.
否则,将记录服务级别的所有消息。 Infrastructure messages (transactions, peer channel, and security) are also logged at this level, except for Reliable Messaging messages.
除了“可靠消息传递”消息外,还会在此级别记录基础结构消息(事务,对等通道和安全性)。 On streamed messages, only the headers are logged.
在流式消息上,仅记录头。 In addition, secure messages are logged decrypted at this level.
此外,安全消息在此级别被记录为解密。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.