Reputation: 20733
To do some WCF benchmarking, I need to have a way to get the size of the exchanged data(with all header(even TCP)/compression/...).
It's in a bigger benchmarking(which also tries different binding, encoding, ...) so I need to do it programmatically and NOT through something like wireshark.
Is there a hook somewhere to do this?
All channels/bindings/encoders are created programmatically to automate some tests.
I found some ways( http://devlicio.us/blogs/derik_whittaker/archive/2011/02/03/how-to-intercept-a-wcf-message-to-track-message-size.aspx ), but I'm not sure it will work with non-text data. Or http://zamd.net/2008/08/15/calculating-wcf-message-size/ but I don't see how to start it(and not sure it will works with my custom encoders
Upvotes: 4
Views: 310
Reputation: 3531
Write a MessageInspector. This will give you an event for all messages. http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.clientruntime.messageinspectors.aspx
You might be able to use WMI performance counters http://msdn.microsoft.com/en-us/library/ms735098.aspx
Upvotes: 2
Reputation: 24416
You have 2 options:
I'm not sure why you prefer the former - I recommend to try wireshark, I'm sure it can be automated too. Anyway if you want to do this inside wcf you should implement a custom message encoder to calaulate the size of bytes that go on the wire. this would need to be a generic encoder that wraps any other encoder inside it. here is an example for a generic encoder. note that the encoder approach will only consider the message size, but not any framing on top of it (HTTP headers for example). This is why I think wireshark is better for your case.
Upvotes: 0