开发者

Routing traffic to ASP.NET Webservice, not working like I want

I have done this:

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)
    {
        r开发者_开发技巧eturn new WebServiceHandlerFactory().GetHandler(HttpContext.Current,
             "*",
             _VirtualPath,
             HttpContext.Current.Server.MapPath(_VirtualPath));
    }
}

What I'm trying to do is that instead of call WebService.asmx I want the users of my webservice call v1/ so to get info from my webservice I normally HTTP POST /Webservice.asmx/MyFunction with post data like id=123

Instead of call /Webservice.asmx/MyFunction I want the url to be /v1/MyFunction

Some ideas how I can do this because I am not getting it to work as I want...


Check out this article on how to successively implement a web-service:

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

Also on public IHttpHandler GetHttpHandler try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜