Get HttpHandler for asp.net web service

Anatoxis

New Member
I'm using asp.net \[code\]RouteTable\[/code\] to register a custom route for a WebService, however asp.net WebServices do not inherit from \[code\]IHttpHandler\[/code\] interface making it it neither simple nor clean to pass the call on to the underlying \[code\]HttpHandler\[/code\].Right now, the only official/documented way is to use \[code\]WebServiceHandlerFactory\[/code\] to get the right handler for the service:\[code\]IHttpHandler handler = new WebServiceHandlerFactory().GetHandler(HttpContext.Current, "*", "url", "path");\[/code\]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 \[code\]WebServiceHandlerFactory\[/code\] using reflection and call the internal \[code\]CoreGetHandler\[/code\] method:\[code\]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 });\[/code\]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 \[code\]HttpHandler\[/code\] for an asp.net WebService solely based on its type rather than its virtual path?
 
Back
Top