Adding WCF Restful service to an existing ASP.Net Website

.net, asp.net, c#, wcf

Solution

You don't need any `*.svc` file for a WCF REST service - you can activate it using a `ServiceRoute` - see RESTful WCF Services with No svc file and No config for a great explanation.

Basically what it boils down to is adding a `ServiceRoute` to your route table in `global.asax`:

protected void Application_Start(object sender, EventArgs e)
{
    RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), 
                                           typeof(YourService)));
}

Problem

I am trying to add a wcf restful service to my existing asp.net 4.0 website (not mvc). I am finding hard time trying to find a good tutorial that walks through in adding one to an existing app/website. Everywhere I see there are notes on creating a new project (with wcf restful template). What are the basic steps? can I do this without an .svc file since I am on .net 4.0? Any tutorial you can point me to? So far i've tried adding a IService.cs and Service.cs classes that define service contracts and uses webinvoke/webget attributes, added routes in global.asax and service definitions in web.cong as shown in this tutorial http://www.codeproject.com/Articles/255684/Create-and-Consume-RESTFul-Service-in-NET-Framewor but when I point to localhost/restservice, I get 404 not found. update: This is what I have in my config file. Note that is an existing wcf soap based service. ``` <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="migrationServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <bindings> <basicHttpBinding> <binding name="migrationHttpBinding" maxBufferSize ="104857600" maxReceivedMessageSize="104857600"/> </basicHttpBinding> </bindings> <services> <service name ="Site.Web.WebService.MigrationService" behaviorConfiguration="migrationServiceBehavior"> <endpoint binding="basicHttpBinding" bindingConfiguration="migrationHttpBinding" contract="Site.Web.WebService.IMigrationService"/> </service> </services> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> </system.serviceModel> ```

Original source