Logging WCF message sizes

旧时模样 提交于 2019-12-10 17:55:00

问题


I am using WCF to send some Linq objects across the wire. I want to log message size either using Message logging or tracing. I don't however want, or have the ability to use the config file to set this up. I am struggling to figure out how to do this programatically. I don't care if this happens at the host of client. I control both.

Does anyone have experience doing this?


回答1:


Marc's right, Message Inspectors will allow you to do this. Create a class that: Implements IDispatchMessageInspector. The below method will be made available where you can implement code to manipulate the request message.

Public Function AfterReceiveRequest(ByRef request As System.ServiceModel.Channels.Message, ByVal channel As System.ServiceModel.IClientChannel, ByVal instanceContext As System.ServiceModel.InstanceContext) As Object Implements System.ServiceModel.Dispatcher.IDispatchMessageInspector.AfterReceiveRequest
    'Output the request message to immediate window
    System.Diagnostics.Debug.WriteLine("*** SERVER - RECEIVED REQUEST ***")
    System.Diagnostics.Debug.WriteLine(request.ToString())

    Return Nothing
End Function

Also, the following Link may also provide some help.

Good Luck




回答2:


Not programming, but perhaps: wireshark?

Alternatively, look into message inspectors. I don't have a specific example for size logging, though.




回答3:


You could also use Fiddler, which can log your HTTP messages if your using one of the wsHttp or basicHttp bindings. http://www.fiddler2.com/fiddler2/



来源:https://stackoverflow.com/questions/899741/logging-wcf-message-sizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!