Search code examples
wcfnettcpbindingperfmonmeasure

Measuring "total bytes sent" from web service with nettcpbinding using perfmon


I have a web service (WCF) exposing both http endpoints and a tcp endpoint (using the nettcpbinding). I am trying to measure the difference in "total bytes sent" using the different endpoints.

I have tried using perfmon and looked at the performance counter: web service > total bytes sent. However it looks like that this only measures http traffic - can any of you confirm this? It doesn't look like tcp traffic increments the number.

There is also a TCP category in perfmon, but there is not a "total bytes sent". Is perfmon the wrong tool for the job?


Solution

  • Solved. I measured bytes received on the client by using code something similar to:

    NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
    NetworkInterface lan = null;
    
           foreach (NetworkInterface networkInterface in interfaces)
            {
                if (networkInterface.Name.Equals("Local Area Connection"))
                {
                    lan = networkInterface;
                }
            }
    
            IPv4InterfaceStatistics stats = lan.GetIPv4Statistics();
            Console.WriteLine("bytes received: " + stats.BytesReceived);
    

    Do this before and after the web service call and diff the 2 values. Obviously you need to be aware that any other traffic on the client does not interfere.