4

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

J4N
  • 19,480
  • 39
  • 187
  • 340
  • 1
    It seems you already has an answer. By employing some endpoint behaviours you can find the size as stated in the links you have provided. On the otherhand, I believe employing wireshark is still a better option when observing size of messages since you can observe protocol related overheads. I feel you will endup with writing your custom fiddler or wireshark. – daryal May 25 '12 at 07:40
  • Tests will be done on the same workstations, so I think that wireshark will not read them. In addition, I really need those test to be automated – J4N May 25 '12 at 11:21
  • 2
    Fiddler reads the values, but for the automation side, you will end up with writing another program for listening network packages. – daryal May 25 '12 at 17:04
  • I checked, fiddler doesn't even saw my localhost request. – J4N Jun 18 '12 at 14:09
  • 1
    According to the doc, I've to set the destination/host to something like `http://ipv4.fiddler`. But I will not allways use `http` protocol – J4N Jun 18 '12 at 14:18

2 Answers2

2

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

IvoTops
  • 3,463
  • 17
  • 18
  • Hi, thanks for the response. Is the MessageInspector taking in account all layer data?(like http,...)? If yes, its what I need! – J4N Jun 19 '12 at 18:35
  • "Implement AfterReceiveReply to inspect or modify a reply message after it has been received by the client object but before it is deserialized into objects that are returned to the client application." So you get the actual message, but not the lower level protocol wrappers I think. – IvoTops Jun 26 '12 at 11:43
0

You have 2 options:

  • use WCF extensibility. this will typically be more work, and you will need to consider various wcf situations.
  • use out of band solution like wireshark

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.

Community
  • 1
  • 1
Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158