繁体   English   中英

获取用于ASP.NET Web服务的HttpHandler

[英]Get HttpHandler for asp.net web service

我正在使用asp.net RouteTable为WebService注册自定义路由,但是asp.net WebServices不继承自IHttpHandler接口,因此将调用传递给基础HttpHandler既不简单也不干净。

现在,唯一的官方/书面方法是使用WebServiceHandlerFactory来获取服务的正确处理程序:

IHttpHandler handler = new WebServiceHandlerFactory().GetHandler(HttpContext.Current, "*", "url", "path");

但是,这需要服务的虚拟路径,这不是我想要的! 我发现的另一个解决方法实际上是使用反射侵入WebServiceHandlerFactory并调用内部CoreGetHandler方法:

var wshf = new WebServiceHandlerFactory();
var coreGetHandler = wshf.GetType().GetMethod("CoreGetHandler", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
var httpHandler = (IHttpHandler)coreGetHandler.Invoke(wshf, new object[] { typeof(MyWebService), context, context.Request, context.Response });

但这不是官方/记录的方法,并且可能在将来的版本中更改,所以我的问题是,是否有任何方法可以仅基于其类型而不是其虚拟路径来为asp.net WebService获取正确的HttpHandler

除了传统的asmx Web服务之外,还有一种替代方法,使用WCF Web服务更加容易和可扩展。 我终于从这里找到了如何将WCF服务与IIS路由管道集成的解决方案

这是一个简短的摘要:

RouteTable.Routes.Add(new ServiceRoute("CustomServiceAddress", new ServiceHostFactory(), typeof(WCFService)));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM