Simple URL routes in WCF Rest 4.0 without trailing slash

后端 未结 7 1437
太阳男子
太阳男子 2021-02-01 20:27

I have a WCF REST 4.0 project based on the the WCF REST Service Template 40(CS). I\'d like to expose simple service endpoint URLs without trailing slashes. For example:

7条回答
  •  花落未央
    2021-02-01 20:55

    Try changing your code in the Global.asax from...

    Routes.Add(new ServiceRoute("cars", new WebServiceHostFactory(), typeof(CarService))); RouteTable.Routes.Add(new ServiceRoute("trucks", new WebServiceHostFactory(), typeof(TruckService)));

    ...to...

    WebServiceHostFactory factory = new WebServiceHostFactory();

    Routes.Add(new ServiceRoute("cars", factory, typeof(CarService))); RouteTable.Routes.Add(new ServiceRoute("trucks", factory, typeof(TruckService)));

提交回复
热议问题