views:

563

answers:

3

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?

A: 

Not programming, but perhaps: wireshark?

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

Marc Gravell
A: 

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/

jrista
+1  A: 

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

Tanner