我已经看到如何使用这样的代码将自定义路由添加到WebForms。我可以在ASP.NET MVC站点中路由Web服务(ASMX)的URL吗?
public class WebFormsRouteHandler : IRouteHandler
{
public string VirtualPath { get; set; }
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// Compiles ASPX (if needed) and instantiates the web form
return (IHttpHandler) BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof (IHttpHandler));
}
}
我试图得到类似的东西的工作,但对于Web服务的文件,因为该页面不从的IHttpHandler继承(TestService.asmx),以前的方法抛出异常。我已经看到了使用WebServiceHandlerFactory这样
return new WebServiceHandlerFactory().GetHandler(context, requestType, url, pathTranslated);
,像我需要返回IHttpHandler的一些其他的代码,但它需要通过一个HttpContext的,但我有机会为过的RequestContext的一部分的唯一的事情是HttpContextBase。从我可以告诉我不能转换为HttpContext。
任何想法?或者,也许有另一种方式去解决它?我试图完成的是通过正常的路由系统来控制我的Web服务的URL。一个例子是想让TestService.asmx成为ExampleTestService /。
我得到了部分成功。我可以得到我的自定义URL来调出Web服务,但尝试调用它时会失败。 – 2009-06-25 05:15:14
然后你最好的机会是通过ASP.NET代码进行调试,如果失败,找出原因...... – chris166 2009-06-25 05:46:35