【问题标题】:Routing traffic to ASP.NET Webservice, not working like I want将流量路由到 ASP.NET Webservice,不能像我想要的那样工作
【发布时间】:2011-10-09 09:25:43
【问题描述】:

我已经这样做了:

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,我希望我的 Web 服务的用户调用 v1/,以便从我的 Web 服务获取信息,我通常使用 HTTP POST /Webservice.asmx/MyFunction 以及像 id 这样的发布数据=123

而不是调用 /Webservice.asmx/MyFunction 我希望 url 是 /v1/MyFunction

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

【问题讨论】:

  • 您遇到的错误是什么?
  • 你有没有想过使用IIS URL Rewrite
  • 当前路由重定向到什么路径(如果有)?

标签: c# asp.net web-services


【解决方案1】:

查看这篇关于如何连续实现网络服务的文章:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多