Search code examples
wcfazurebandwidth

Calculating total bytes sent with a WCF service operation


I am testing an Azure worker role that offers 10-12 different service operations that are available to WPF desktop clients. I am keeping an eye on the total outgoing bandwidth via the Azure billing portal. It seems these operations are generating more outgoing bandwidth than I had anticipated.

Is there any way to "measure" the total download size of each service operation from the WPF client perspective? I know C# doesn't have an equivalent sizeof operator so I figure I can't just do a

sizeof(List<MyObjects>) 

to see total bytes being transferred for any particular call.

I thought about maybe using wireshark and somehow tally up packet sizes for each service operation call and finding the bandwidth hogs in this manner.

Is there an easier way to do this?


Solution

  • The performance counters are good to calculate the total bytes sent/received. But if you want to know the amount per operation call, you'll need to write a message inspector on the side of the service.

    This will allow you to intercept each incoming and outgoing message and you'll have access to the raw Message object, allowing you to measure the total size of the request and the response.