将流量路由到ASP.NET Webservice,而不是像我想要的那样工作

时间:2011-10-09 09:25:43

标签: c# asp.net web-services

我做到了:

public class Global : System.Web.HttpApplication
{

    protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        RouteTable.Routes.Add("v1", new Route("v1/{action}", null, null, null, new WebServiceRouteHandler("~/WebService.asmx")));
    }
}

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));
    }
}

我正在尝试做的是,而不是调用WebService.asmx我希望我的webservice的用户调用v1 / so从我的webservice获取信息我通常HTTP POST /Webservice.asmx/MyFunction与post数据如id = 123

我希望网址为/ v1 / MyFunction

而不是调用/Webservice.asmx/MyFunction

有些想法我是如何做到这一点的,因为我没有让它按照我想要的方式工作......

1 个答案:

答案 0 :(得分:0)

查看有关如何连续实施Web服务的文章:

http://mikehadlow.blogspot.ro/2007/03/writing-raw-web-service-using.html

同样在public IHttpHandler GetHttpHandler试试这个

Return New WebServiceHandlerFactory().GetHandler(HttpContext.Current, "*", "/Build/WebService.asmx", HttpContext.Current.Server.MapPath(aspxyouNeedToLoad))