我一直在寻找一种路线http://www.example.com/WebService.asmx http://www.example.com/WebService.asmx to http://www.example.com/service/ http://www.example.com/service/仅使用 ASP.NET 3.5 路由框架,无需配置 IIS 服务器。
到目前为止,我已经完成了大多数教程告诉我的操作,添加了对路由程序集的引用,在 web.config 中配置了内容,并将其添加到了全局.asax:
protected void Application_Start(object sender, EventArgs e)
{
RouteCollection routes = RouteTable.Routes;
routes.Add(
"WebService",
new Route("service/{*Action}", new WebServiceRouteHandler())
);
}
...创建了这个类:
public class WebServiceRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// What now?
}
}
……问题就在那里,我不知道该怎么办。我读过的教程和指南使用页面路由,而不是 Web 服务。这可能吗?
Ps: 路由处理程序正在工作,我可以访问/服务/它抛出了未实现异常我离开在获取HttpHandler method.
只是想我会根据对我有用的 Markives 给出的答案,用更详细的解决方案来完善这个问题。
首先是路由处理程序类,它将 WebService 的虚拟目录作为其构造函数参数。
public class WebServiceRouteHandler : IRouteHandler
{
private string _VirtualPath;
public WebServiceRouteHandler(string virtualPath)
{
_VirtualPath = virtualPath;
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new WebServiceHandlerFactory().GetHandler(HttpContext.Current,
"*",
_VirtualPath,
HttpContext.Current.Server.MapPath(_VirtualPath));
}
}
以及 Global.asax 的 Routey 位中此类的实际用法
routes.Add("SOAP",
new Route("soap", new WebServiceRouteHandler("~/Services/SoapQuery.asmx")));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)