.netwcfwcftestclient

What determines the order of methods in WCF Test Client?


WCF Test Client doesn't seem to put methods in any logical order. However, the order is consistent. It remains the same in every environment.

It's not alphabetical. It's not the order of the methods in the class. The order in WCF Test Client does not match the order in the WSDL.

It's not totally random though. The order sometimes matches up with the class. But you can then change around the order in the class, re-compile, and when you add the service back to WCF Test Client, it doesn't change to match.

So what is determining the order?


Solution

  • For the sake of curiosity, I had a look at WcfClientTest.exe source code to find out what the order is.

    The following piece of code is probably where all the methods are populated (disclaimer: I just guessed! No time to verify this):

    endpoint.ClientTypeName = GetContractTypeName(contractType);
    foreach (MethodInfo info in contractType.GetMethods())
    {
    

    So what is the order of the methods which GetMethods returns? According to this MSDN link: https://msdn.microsoft.com/en-us/library/4d848zkb(v=vs.110).aspx

    The GetMethods method does not return methods in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which methods are returned, because that order varies.

    That's all I can find out :)