Host WCF in MVC2 Site

Posted by Basiclife on Stack Overflow See other posts from Stack Overflow or by Basiclife
Published on 2011-01-13T12:43:54Z Indexed on 2011/01/13 12:54 UTC
Read the original article Hit count: 218

Hi,

We've got a very large, complex MVC2 website. We want to add an API for some internal tools and decided to use WCF.

Ideally, we want MVC itself to host the WCF service. Reasons include:

  • Although there's multiple tiers to the application, some functionality we'd like in the API requires the website itself (e.g. formatting emails).
  • We use TFS to auto-build (continuous integration) and deploy - The less we need to modify the build and release mechanism the better
  • We use the Unity container and Inversion of Control throughout the application. Being part of the Website would allow us to re-use configuration classes and other helper methods.

I've written a custom ServiceBehavior which in turn has a custom InstanceProvider - This allows me to instantiate and configure a container which is then used to service all requests for class instances from WCF.

So my question is; Is it possible to host a WCF service from within MVC itself?

I've only had experience in Services / Standard Asp.Net websites before and didn't realise MVC2 might be different until I actually tried to wire it into the config and nothing happened. After some googling, there don't seem to be many references to doing this - so thought I'd ask here.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about wcf