I'm using asp.net RouteTable
to register a custom route for a WebService, however asp.net WebServices do not inherit from IHttpHandler
interface making it it neither simple nor clean to pass the call on to the underlying HttpHandler
.
Right now, the only official/documented way is to use WebServiceHandlerFactory
to get the right handler for the service:
IHttpHandler handler = new WebServiceHandlerFactory().GetHandler(HttpContext.Current, "*", "url", "path");
However, this requires virtual path of the service which is not what I'm looking for! The other workaround I found was actually hacking into WebServiceHandlerFactory
using reflection and call the internal CoreGetHandler
method:
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 });
But it is not an official/documented way to do so and might change in future releases, so my question is that if there's any way to get the right HttpHandler
for an asp.net WebService solely based on its type rather than its virtual path?
There's an alternative to the legacy asmx WebServices, using WCF web services is much more easier and extensible. I finally found the solution how to integrate the WCF service with the IIS routing pipeline from here
Here's a quick snippet:
RouteTable.Routes.Add(new ServiceRoute("CustomServiceAddress", new ServiceHostFactory(), typeof(WCFService)));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.