What determines the order of methods in WCF Test Client?

五迷三道 提交于 2019-12-10 20:56:17

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/29151372/what-determines-the-order-of-methods-in-wcf-test-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!