How to remove the “.svc” extension in RESTful WCF service?

后端 未结 7 899
借酒劲吻你
借酒劲吻你 2020-11-29 17:41

In my knowledge, the RESTful WCF still has \".svc\" in its URL.

For example, if the service interface is like

[OperationContract]
[WebGet(UriTemplate         


        
7条回答
  •  死守一世寂寞
    2020-11-29 18:15

    I know this post is a bit old now, but if you happen to be using .NET 4, you should look at using URL Routing (introduced in MVC, but brought into core ASP.NET).

    In your app start (global.asax), just have the following route configuration line to setup the default route:

    RouteTable.Routes.Add(new ServiceRoute("mysvc", new WebServiceHostFactory(), typeof(MyServiceClass)));
    

    then your URLs would look like this:

    http://servername/mysvc/value/2
    

    HTH

提交回复
热议问题