代码之家  ›  专栏  ›  技术社区  ›  Rob

C#通过url调用webservice

  •  0
  • Rob  · 技术社区  · 14 年前

    我在global.asax上注册了以下路线;

    routes.MapRoute(
                    "ServiceHandler",
                    "{*path}/{*.svc}",
                    new { Url = "Services/Service.svc/GetLatestTweets" }
                    );
    

    http://www.domainname.com/Services/Service.svc/GetLatestTweets
    

    当我使用上面提到的注册路由时,下面添加的stackstrace出现错误。

    [ArgumentException: A catch-all parameter can only appear as the last segment of the route URL.
    Parameter name: routeUrl]
       System.Web.Routing.RouteParser.Parse(String routeUrl) +3823656
       System.Web.Routing.Route..ctor(String url, IRouteHandler routeHandler) +24
       System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults, Object constraints, String[] namespaces) +86
       System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults, Object constraints) +28
       System.Web.Mvc.RouteCollectionExtensions.MapRoute(RouteCollection routes, String name, String url, Object defaults) +18
       CMS.Presentation.FrontEnd.Framework.CMSApplication.RegisterRoutes(RouteCollection routes) in C:\Projects\Website\Web.Presentation\FrontEnd\Framework\CMSApplication.cs:62
       CMS.Presentation.FrontEnd.Framework.CMSApplication.Application_Start() in C:\Projects\Website\Web.Presentation\FrontEnd\Framework\CMSApplication.cs:80
    
    [HttpException (0x80004005): A catch-all parameter can only appear as the last segment of the route URL.
    Parameter name: routeUrl]
       System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +3988565
       System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191
       System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +325
       System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
       System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
    
    [HttpException (0x80004005): A catch-all parameter can only appear as the last segment of the route URL.
    Parameter name: routeUrl]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11529072
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4784373
    

    2 回复  |  直到 14 年前
        1
  •  1
  •   smartcaveman    14 年前

    也许我错过了什么,但你似乎可以

            routes.MapRoute(
                "ServiceHandler",
                "Services/{service}.svc/{*path}",
                new { controller = "services", action = "ParseAndExecuteServiceCall" service = "TwitterService", path = "GetLatestTweets" }
                );
    

    另外,对于下面关于.svc与.mvc处理程序的注释的响应-没有任何东西可以限制您重写IHttpHandler以便执行此操作,您需要重写IRouteHandler In的GetHttpHandler()方法。。。然后你可以做任何你想要的处理。

        2
  •  3
  •   Darin Dimitrov    14 年前

    你不能做到这一点。这个 .svc 为了处理WCF,扩展已经用与MVC非常不同的处理程序注册。如果你试图改变它的服务永远不会工作。您可能需要从控制器操作调用web服务,该操作将充当网桥。