WCF: check exchange size

To do some WCF benchmarking, I need to have a way to get the size of the exchanged data (with all the headers (even TCP) / compression / ...).

In a larger benchmarking (which also tries to distinguish between bindings, coding, ...), so I need to do this programmatically and NOT through something like wireshark.

Is there any hook for this?

All channels / bindings / encoders are created programmatically to automate some tests.

I found several ways ( http://devlicio.us/blogs/derik_whittaker/archive/2011/02/03/how-to-intercept-a-wcf-message-to-track-message-size.aspx ), but I not sure if it will work with non-textual data. Or http://zamd.net/2008/08/15/calculating-wcf-message-size/ , but I don’t see how to start it (and not sure if it will work with my user codes

+4
source share
2 answers

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

+2
source

You have 2 options:

  • use extensibility WCF. this will usually be more work and you will need to consider the various wcf situations.
  • use an out-of-band solution like wirehark

I’m not sure why you prefer the first - I recommend trying wirehark, I’m sure that it can also be automated. In any case, if you want to do this inside wcf, you must implement a special message encoder to size the size of the bytes that go to the wire. it must be a common encoder that any other encoder wraps in. here is an example for a common encoder. note that the encoder approach only considers the size of the message, but does not crop it at the top (for example, HTTP headers). That is why I think wirehark is better for your business.

0
source

Source: https://habr.com/ru/post/1414311/


All Articles