C#-通过目录中的Web服务列表和可用的Web方法列表递增

C#-通过目录中的Web服务列表和可用的Web方法列表递增,c#,web-services,C#,Web Services,我正在构建的C#web应用程序中有许多不同的web服务,我想创建一个快速文档页面,其中列出所有的web服务和每个应用程序中可用的web方法。与每次更改/添加webmethod时都必须保持文档页面最新不同,如果文档是动态的,那就更好了 对于每个webmethod,我希望从webmethod属性中获得Description属性,以及(如果可能的话)每个方法的参数列表 我知道我可以从.NET为.asmx页面提供服务的web服务摘要页面中获得很多这方面的信息,但我不想强迫用户不停地单击主文档页面 提前谢

我正在构建的C#web应用程序中有许多不同的web服务,我想创建一个快速文档页面,其中列出所有的web服务和每个应用程序中可用的web方法。与每次更改/添加webmethod时都必须保持文档页面最新不同,如果文档是动态的,那就更好了

对于每个webmethod,我希望从webmethod属性中获得Description属性,以及(如果可能的话)每个方法的参数列表

我知道我可以从.NET为.asmx页面提供服务的web服务摘要页面中获得很多这方面的信息,但我不想强迫用户不停地单击主文档页面


提前谢谢

一个快速解决方案是编写一个自定义Http处理程序:

public class InformationHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        // Select the assembly that contains the web service classes
        var assemblyThatContainsTheWebService = Assembly.GetExecutingAssembly();

        // Select all types in this assembly deriving from WebService
        var webServiceTypes = 
            from type in assemblyThatContainsTheWebService.GetTypes()
            where type.BaseType == typeof(WebService)
            select type;

        context.Response.ContentType = "text/plain";

        foreach (var type in webServiceTypes)
        {
            context.Response.Write(string.Format("Methods for web service {0}:{1}", type, Environment.NewLine));
            // Select all methods marked with the WebMethodAttribute
            var methods = 
                from method in type.GetMethods()
                where method.GetCustomAttributes(typeof(WebMethodAttribute), false).Count() > 0
                select method;

            foreach (var method in methods)
            {
                context.Response.Write(method);
            }
            context.Response.Write(Environment.NewLine);
        }

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

快速解决方案是编写自定义Http处理程序:

public class InformationHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        // Select the assembly that contains the web service classes
        var assemblyThatContainsTheWebService = Assembly.GetExecutingAssembly();

        // Select all types in this assembly deriving from WebService
        var webServiceTypes = 
            from type in assemblyThatContainsTheWebService.GetTypes()
            where type.BaseType == typeof(WebService)
            select type;

        context.Response.ContentType = "text/plain";

        foreach (var type in webServiceTypes)
        {
            context.Response.Write(string.Format("Methods for web service {0}:{1}", type, Environment.NewLine));
            // Select all methods marked with the WebMethodAttribute
            var methods = 
                from method in type.GetMethods()
                where method.GetCustomAttributes(typeof(WebMethodAttribute), false).Count() > 0
                select method;

            foreach (var method in methods)
            {
                context.Response.Write(method);
            }
            context.Response.Write(Environment.NewLine);
        }

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

很甜蜜。我看到一个挑剔的地方:如果服务关闭,文档也会关闭,但这仍然很好。折叠xml注释也很酷。谢谢darin,这将很好地工作-只是一个说明(对于本文的任何未来浏览器),我正在使用.NET 2.0,所以我只需要用一些条件替换LINQ语句。非常好。我看到一个挑剔的地方:如果服务关闭,文档也会关闭,但这仍然很好。折叠xml注释也很酷。谢谢darin,这将很好地工作-只是一个说明(对于本文的任何未来浏览器),我正在使用.NET2.0,所以我只需要用一些条件替换LINQ语句。