URL rewriting in WCF or Removing svc extension from WCF rest service

Created On : Feb-06-2015 Default Author Author : Abdul Basit
Download Source Code -  27.15 KB

Create a new WCF service application.

Add Global.asax file.

In Application_Start method add below lines:
 RouteTable.Routes.Add(new ServiceRoute("api/Service1", new WebServiceHostFactory(), typeof(Service1)));

Add reference of System.ServiceModel.Activation.

Add WebInvoke in Operation Contract of Service Contract (interface IService1).
      
 [OperationContract]
 [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetData?value={value}")]

Build and browse Project.
Open /api/Service1/GetData?value=5555

Although if you browse Service.svc it will still be served. To disable  Service.svc URL follow below steps:
  1. Right click Service1.svc click View Markup.
  2. Add Factory="System.ServiceModel.Activation.WebServiceHostFactory" in Service markup.

Browse /Service1.svc



comments powered by Disqus