Wednesday, June 5, 2013

Hosting a WCF service inside an ASP.NET MVC project

Adding a WCF service to an ASP.NET MVC project, just choose Add new item and choose the WCF Service item. However when you try to connect to your WCF service(e.g. http://localhost:8000/sampleservice.svc), you’ll end up with the following exception:

“Resource not found”

The WCF service URL interferes with the default MVC routing so instead of loading up the WCF service, the ASP.NET MVC framework tries to find a matching controller and action.

To fix this, extend the routing with 2 extra ignores:

6 comments:

my asp said...

wow!!! windows communication foundations is the biggest platform for developing any project with secure.Thank you so much for developing your hosting application in a new direction.Though I also belongs to one of webmaster So I am keen interest to touch of this wcf applications.And wants some more information about?Thanks...

James Hayden said...

Hosting a WCF service inside an ASP.NET MVC project is a great experiment for me .Though we know that windows communication foundation is a great area where we can make our appliaction more secure as well as more trust worthy.so I am trying to make my project at mywindowshosting.com must be better by implementing tricks which you have implemented so vastly.

Jason Michas said...

The alternative is to put a route in explicitly for your service like:
routes.Add(new ServiceRoute("myservice",new ServiceHostFactory(), typeof(MyWCFService)));

sella said...

Thanks Mr Bart.
your experiment is a great idea. I've been searching to Hosting a WCF service inside an ASP.NET MVC project. and now it solved because you.

Lino said...

It is "The art of simplicity", Thanks...

Shane Larson said...

That was amazingly easy. Thanks for the quick tutorial.