5

How can I programatically get a list of public methods w/parameters that are exposed in my webAPI project? I need to provide this list to our QA dept. I dont want to compile and maintain the list myself. I want to provide a link for QA to find the methods on their own. I need something like what you get when you browse to an .asmx file.

sme
  • 75
  • 1
  • 1
  • 6
  • Web API provides HelpPage...for more you can look at this article: http://blogs.msdn.com/b/yaohuang1/archive/2012/08/15/introducing-the-asp-net-web-api-help-page-preview.aspx – Kiran Sep 26 '13 at 21:02
  • Note that the above video is more than year old, but it could still give you some useful info. – Kiran Sep 26 '13 at 21:03

3 Answers3

7

ASP.NET Web API lets you create a help page automatically. That help pages documents all endpoints provided by your API. Please refer to this blog post: Creating Help Pages for ASP.NET Web API.

You can, of course, create an entirely custom documentation by leveraging the IApiExplorer interface.

Marius Schulz
  • 15,976
  • 12
  • 63
  • 97
0

You may try something like this:

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

I got it from here

Dmitresky
  • 536
  • 8
  • 21
0

Here's a quote from Scott Gu that answers your question:

Web API doesn't directly support WSDL or SOAP. You can use the WCF REST support if you want to use a WCF/WSDL based model to support both SOAP and REST though.

Your question was asked and answered here as well: ASP.NET Web API interface (WSDL)

Hope that helps.

Community
  • 1
  • 1
inliner49er
  • 1,300
  • 1
  • 11
  • 19