mil*_*n m 9 c# asp.net web-services routes asp.net-routing
注意:此代码中没有MVC.纯旧的Web表单和
.asmx
Web服务.
我.asmx
在我的新公司继承了一个大规模的ASP.NET Web Forms和Web Service()应用程序.
由于某些需要,我正在尝试为所有Web窗体执行URL路由,这是我成功完成的.
现在.asmx
,routes.MapPageRoute
不起作用.根据下面的文章,我创建了一个IRouteHandler
类.以下是代码的外观:
using System;
using System.Web;
using System.Web.Routing;
using System.Web.Services.Protocols;
using System.Collections.Generic;
public class ServiceRouteHandler : IRouteHandler
{
private readonly string _virtualPath;
private readonly WebServiceHandlerFactory _handlerFactory = new WebServiceHandlerFactory();
public ServiceRouteHandler(string virtualPath)
{
if (virtualPath == null)
throw new ArgumentNullException("virtualPath");
if (!virtualPath.StartsWith("~/"))
throw new ArgumentException("Virtual path must start with ~/", "virtualPath");
_virtualPath = virtualPath;
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// Note: can't pass requestContext.HttpContext as the first parameter because that's
// type HttpContextBase, while GetHandler wants HttpContext.
return _handlerFactory.GetHandler(HttpContext.Current, requestContext.HttpContext.Request.HttpMethod, _virtualPath, requestContext.HttpContext.Server.MapPath(_virtualPath));
}
}
Run Code Online (Sandbox Code Playgroud)
http://mikeoncode.blogspot.in/2014/09/aspnet-web-forms-routing-for-web.html
现在,当我进行路由时Global.asax
,它适用于根文档文件,但不适用于我的.asmx
文件中的Web方法.
routes.Add("myservice", new System.Web.Routing.Route("service/sDxcdfG3SC", new System.Web.Routing.RouteValueDictionary() { { "controller", null }, { "action", null } }, new ServiceRouteHandler("~/service/myoriginal.asmx")));
routes.MapPageRoute("", "service/sDxcdfG3SC", "~/service/myoriginal.asmx");
Run Code Online (Sandbox Code Playgroud)
我想将.asmx
Web方法URL 映射www.website.com/service/myservice.asmx/fetchdata
到具有模糊名称的URL,就像www.website.com/service/ldfdsfsdf/dsd3dfd3d
使用.NET Routing一样.
如何才能做到这一点?
这不是一个直接的答案,但值得考虑。
您可以将 ASMX 服务升级到具有兼容合同的 WCF 服务,这样您就根本不需要升级您的客户端。
这样,您就可以使用已知的技术来动态路由 WCF 服务。由于这种已知技术涉及服务的任意地址,因此您可以将 WCF 服务绑定到.......foo.asmx
端点地址,以便您的客户端不仅不会升级其客户端代理,而且还具有完全相同的端点地址。
换句话说,对于客户端来说,动态路由的 WCF 服务看起来与旧的 ASMX 服务一模一样。
过去几年我们成功地使用这种技术将大多数旧的 ASMX 升级到 WCF,在许多情况下保留了客户端代理。
所有技术细节都记录在我的博客文章中
http://www.wiktorzychla.com/2014/08/dynamic-wcf-routing-and-easy-upgrading.html
归档时间: |
|
查看次数: |
2315 次 |
最近记录: |