簡體   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