Note that there are some explanatory texts on larger screens.

plurals
  1. POHost WCF in MVC2 Site
    primarykey
    data
    text
    <p>We've got a very large, complex MVC2 website. We want to add an API for some internal tools and decided to use WCF.</p> <p>Ideally, we want MVC itself to host the WCF service. Reasons include:</p> <ul> <li>Although there's multiple tiers to the application, some functionality we'd like in the API requires the website itself (e.g. formatting emails).</li> <li>We use TFS to auto-build (continuous integration) and deploy - The less we need to modify the build and release mechanism the better</li> <li>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.</li> </ul> <p>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.</p> <p>So my question is; Is it possible to host a WCF service from within MVC itself?</p> <p>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 <em>nothing happened</em>. After some googling, there don't seem to be many references to doing this - so thought I'd ask here.</p> <p><strong>More Detail:</strong></p> <p>Thanks to those of you who replied but I'm still having issues getting this to work... My current config looks like this:</p> <pre><code>&lt;system.serviceModel&gt; &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"&gt; &lt;serviceActivations&gt; &lt;add relativeAddress="Job.svc" service="MyApplication.WebJobManager" factory="System.ServiceModel.Activation.WebServiceHostFactory" /&gt; &lt;/serviceActivations&gt; &lt;/serviceHostingEnvironment&gt; &lt;extensions&gt; &lt;behaviorExtensions&gt; &lt;add name="WCFDIBehavior" type="MyApplication.Jobs.WCFDIBehaviorExtension, MyApplication.Jobs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt; &lt;/behaviorExtensions&gt; &lt;/extensions&gt; &lt;standardEndpoints&gt; &lt;mexEndpoint&gt; &lt;standardEndpoint name="WebJobManagerMex" /&gt; &lt;/mexEndpoint&gt; &lt;/standardEndpoints&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="JobServiceBehavior"&gt; &lt;serviceMetadata /&gt; &lt;WCFDIBehavior /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;services&gt; &lt;service behaviorConfiguration="" name="MyApplication.Jobs.WebJobManager"&gt; &lt;endpoint binding="basicHttpBinding" bindingConfiguration="" name="HTTPEndpoint" contract="MyApplication.JobService.Interfaces.IWebJobManager" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;/system.serviceModel&gt; </code></pre> <p>Can someone please tell me if anything looks obviously wrong?</p> <p>I was expecting to find the endpoint at <code>http://localhost/MyApplication/Job.svc</code> and metadata at <code>http://localhost/MyApplication/Job.svc?mex</code> however, both give a 404 - As far as I can tell, there's no obvious sign that WCF is running at all. Do I perhaps need to do something to my routes?</p> <p><strong>NB:</strong> In case others have this problem, I had to add <code>routes.IgnoreRoute("{MyJob}.svc/{*pathInfo}")</code> to the Route setup in <code>Global.asax</code> to prevent MVC intercepting the call.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload