Asp.Net 3.5路由到web服务? [英] Asp.Net 3.5 Routing to Webservice?

查看:190
本文介绍了Asp.Net 3.5路由到web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方式来路由 http://www.example.com/WebService.asmx 以< A HREF =htt​​p://www.example.com/service/> http://www.example.com/service/ 只使用ASP.NET 3.5路由架构,而无需配置IIS服务器

I was looking for a way to route http://www.example.com/WebService.asmx to http://www.example.com/service/ using only the ASP.NET 3.5 Routing framework without needing to configure the IIS server.

到现在为止我已经做了大多数的教程告诉我,加入路由集的引用,在web.config配置的东西,已将此添加在 Global.asax中

Until now I have done what most tutorials told me, added a reference to the routing assembly, configured stuff in the web.config, added this to the Global.asax:

protected void Application_Start(object sender, EventArgs e)
{
    RouteCollection routes = RouteTable.Routes;

    routes.Add(
        "WebService",
        new Route("service/{*Action}", new WebServiceRouteHandler())
    );
}

...创建此类:

...created this class:

public class WebServiceRouteHandler : IRouteHandler
{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        // What now?
    }
}

......,问题就在那里,我不知道该怎么办。本教程和指南我读过使用路由的页面,而不是Web服务。这甚至可能?

...and the problem is right there, I don't know what to do. The tutorials and guides I've read use routing for pages, not webservices. Is this even possible?

:路由处理程序的工作,我可以访问的 /服务/ 的,它引发的 NotImplementedException 的我留在 GetHttpHandler 的方法。

Ps: The route handler is working, I can visit /service/ and it throws the NotImplementedException I left in the GetHttpHandler method.

推荐答案

只是想我要圆了这个问题更详细的解决方案基于为我工作Markives给出的答案了一下。

Just thought I would round off this question with a bit more of a detailed solution based on the answer given by Markives that worked for me.

首先这里是路由处理类,它采用虚拟目录到你的WebService作为它的构造函数参数。

Firstly here is the route handler class which takes the virtual directory to your WebService as its constructor param.

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位内的实际使用情况

and the actual usage of this class within the routey bit of Global.asax

routes.Add("SOAP",
    new Route("soap", new WebServiceRouteHandler("~/Services/SoapQuery.asmx")));

这篇关于Asp.Net 3.5路由到web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆