2013-09-26 80 views
4

如何以编程方式获取公开方法w /参数在我的webAPI项目中公开的列表?我需要将此列表提供给我们的质量检查部门。我不想自己编译和维护列表。我想为QA提供一个链接,以便自己查找方法。我需要像浏览到.asmx文件时获得的内容。如何获得WebAPI项目中暴露的方法?

+0

Web API提供了HelpPage ...更多你可以看看这篇文章:http://blogs.msdn.com/b/yaohuang1/archive/2012/08/15/introducing-the-asp-net-web -api-help-page-preview.aspx –

+0

请注意,上面的视频已超过一年,但它仍然可以给你一些有用的信息。 –

回答

5

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

您当然可以通过利用IApiExplorer界面创建完全自定义的文档。

0

你可以尝试这样的事:

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); 
     } 
    } 

我从here

0

这里得到它是从斯科特谷的报价,回答你的问题:

的Web API没有按” t直接支持WSDL或SOAP。如果您想使用基于WCF/WSDL的模型来同时支持SOAP和REST,则可以使用WCF REST支持。

你的问题被问和在这里找到答案还有: ASP.NET Web API interface (WSDL)

希望有所帮助。