C# 如何在webAPI项目中公开方法?

C# 如何在webAPI项目中公开方法?,c#,reflection,asp.net-web-api,wcf-web-api,C#,Reflection,Asp.net Web Api,Wcf Web Api,如何以编程方式获取webAPI项目中公开的带有参数的公共方法列表?我需要把这份清单提供给我们的质量保证部门。我不想自己编辑和维护这份清单。我想为QA提供一个链接,让他们自己找到方法。我需要一些类似于浏览.asmx文件时得到的内容。您可以尝试以下内容: public static void Main() { Type myType =(typeof(MyTypeClass)); // Get the public methods. Meth

如何以编程方式获取webAPI项目中公开的带有参数的公共方法列表?我需要把这份清单提供给我们的质量保证部门。我不想自己编辑和维护这份清单。我想为QA提供一个链接,让他们自己找到方法。我需要一些类似于浏览.asmx文件时得到的内容。

您可以尝试以下内容:

public static void Main() 
    {
        Type myType =(typeof(MyTypeClass));
        // Get the public methods.
        MethodInfo[] myArrayMethodInfo = myType.GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);
        Console.WriteLine("\nThe number of public methods is {0}.", myArrayMethodInfo.Length);
        // Display all the methods.
        DisplayMethodInfo(myArrayMethodInfo);
        // Get the nonpublic methods.
        MethodInfo[] myArrayMethodInfo1 = myType.GetMethods(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly);
        Console.WriteLine("\nThe number of protected methods is {0}.", myArrayMethodInfo1.Length);
        // Display information for all methods.
        DisplayMethodInfo(myArrayMethodInfo1);      
    }
    public static void DisplayMethodInfo(MethodInfo[] myArrayMethodInfo)
    {
        // Display information for all methods. 
        for(int i=0;i<myArrayMethodInfo.Length;i++)
        {
            MethodInfo myMethodInfo = (MethodInfo)myArrayMethodInfo[i];
            Console.WriteLine("\nThe name of the method is {0}.", myMethodInfo.Name);
        }
    }
publicstaticvoidmain()
{
类型myType=(typeof(MyTypeClass));
//获取公共方法。
MethodInfo[]myArrayMethodInfo=myType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
WriteLine(“\n公共方法的数量为{0}.”,myArrayMethodInfo.Length);
//显示所有方法。
DisplayMethodInfo(myArrayMethodInfo);
//获取非公共方法。
MethodInfo[]myArrayMethodInfo1=myType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
WriteLine(“\n受保护方法的数量为{0}.”,myArrayMethodInfo1.Length);
//显示所有方法的信息。
DisplayMethodInfo(myArrayMethodInfo1);
}
公共静态void DisplayMethodInfo(MethodInfo[]myArrayMethodInfo)
{
//显示所有方法的信息。

对于(inti=0;i,这里引用Scott Gu的一句话来回答您的问题:

Web API不直接支持WSDL或SOAP。但是,如果希望使用基于WCF/WSDL的模型同时支持SOAP和REST,则可以使用WCF REST支持

你的问题在这里也得到了回答:


希望对您有所帮助。

ASP.NET Web API允许您自动创建帮助页。该帮助页记录了API提供的所有端点。请参阅此博文:


当然,您可以通过利用
IApiExplorer
界面创建一个完全定制的文档。

webapi提供了帮助页……更多信息,请参阅本文:注意,上面的视频已有一年多的历史了,但它仍然可以为您提供一些有用的信息。