I have a web application in MVC4. I\'m going to host in on a shared hosting provider. I want to extend it with a WCF service for uploading files. (There wil
Since you're already building an MVC4 app, you might as well consider using MVC4 + Web API since those work together without any issues (Web API is previously known WCF REST).
If you still decide to stick with WCF, I wouldn't mix it in the same project with MVC4 application but rather host it as additional IIS application, side-by-side with MVC4.
I finally found how to make it work.
In your MVC app Web.config add:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
In your routes config ---> Global.asax or App_Start/RoutesConfig (depending on MVC version) add:
public static void RegisterRoutes(RouteCollection routes)
{
...
routes.Add(new ServiceRoute("hello", new ServiceHostFactory(), typeof(YourServiceClass)));
...
}
And that's it. Now your service appears under localhost/hello or wherever you deploy your app.
This uses BasicHttpBinging by default. If you need other you have to implement your own ServiceHostFactory. From what I observed, this method only works for HTTP bindings. When I tried to add a NetTcpBinding it failed.
We do this all the time in the following way: