Question

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?

Was it helpful?

Solution

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

OTHER TIPS

Not programming, but perhaps: wireshark?

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

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top