Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top