3

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?

Yoh Deadfall
  • 2,711
  • 7
  • 28
  • 32
friggle
  • 3,362
  • 3
  • 35
  • 47
  • 1
    Why do you need it? Can you please explain this? – VMAtm Apr 06 '15 at 11:52
  • If you're just looking for a way to find certain service method in the operations list, you can [type the name of the method](http://stackoverflow.com/questions/14695156/listing-service-operations-alphabetically-in-wcf-test-client-wcftestclient-exe?rq=1). – CodeCaster Apr 06 '15 at 11:53
  • My original goal was just to find a way to re-order them, so others in my organization could more easily find their way around large services. After finding that the order wasn't malleable, I wanted to know why. Typing the name is helpful, but I mainly wanted to discover what drives the order/lack-thereof. – friggle Apr 06 '15 at 15:52

1 Answers1

5

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 :)

Thuan
  • 1,618
  • 1
  • 10
  • 21
  • Wow, that sounds like the answer. That would explain why it usually follows the contract order, but sometimes appears to adhere to an order of its own: the CLR has found it efficient to re-organize some methods for whatever reason. – friggle Apr 06 '15 at 15:39