title: Orchard/MVC WCF Service Url with Area
body: <p>Bertrand created a blog <a href="http://weblogs.asp.net/bleroy/archive/2011/04/20/orchard-1-1-what-s-in-it-for-developers.aspx" rel="nofollow">post</a> to specify how to use IoC in WCF Modules for Orchard.</p>
  
  <p>In 1.1, you can create a SVC file using the new Orchard host factory:</p>
  
  <pre><code>&lt;%@ ServiceHost Language="C#" Debug="true" 
      Service="MyModule.IMyService, MyAssembly"
      Factory="Orchard.Wcf.OrchardServiceHostFactory, Orchard.Framework" %&gt;
  Then register your service normally as an IDependency but with service and operation contract attributes:
  
  using System.ServiceModel;
  
  namespace MyModule {
      [ServiceContract]
      public interface IMyService : IDependency {
          [OperationContract]
          string GetUserEmail(string username);
      }
  }
  </code></pre>
  
  <p>My question is that all of Orchard's modules are really area's. So how can you build a route that hits the svc file created in the area/module? </p>
  
  <p>Should you use the full physical path to get to the svc file (tried that and it caused a web.config issue since it was bridging a site and area). </p>
  
  <pre><code>http://localhost/modules/WebServices/MyService.svc
  </code></pre>
  
  <p>Or do you create a ServiceRoute with WebServiceHostFactory/OrchardServiceHostFactory?</p>
  
  <pre><code>new ServiceRoute("WebServices/MyService", new OrchardServiceHostFactory(), typeof(MyService))
  </code></pre>
  
  <p>Whatever I try I get a 404 when trying to hit the resource. I was able to get this working using a wcf Application project and setting WCF as a stand alone application, my issues started when trying to bring it into Orchard/MVC.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks for the help Piotr,</p>
  
  <p>This is the steps I took to implement the service.</p>
  
  <p>Routes.cs</p>
  
  <pre><code>new RouteDescriptor {   Priority = 20,
                          Route = new ServiceRoute(
                                        "Services",
                                        new WebServiceHostFactory(),
                                        typeof(MyService)) }
  </code></pre>
  
  <p>If I use OrchardServiceHostFactory() instead of WebServiceHostFactory() I get the following error. </p>
  
  <pre><code>Operation is not valid due to the current state of the object.
  </code></pre>
  
  <p>Orchard Root Web.Config</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/&gt;
      &lt;standardEndpoints&gt;
        &lt;webHttpEndpoint&gt;
          &lt;!-- 
              Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
              via the attributes on the &lt;standardEndpoint&gt; element below
          --&gt;
          &lt;standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/&gt;
        &lt;/webHttpEndpoint&gt;
      &lt;/standardEndpoints&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>MyService</p>
  
  <pre><code>[ServiceContract]
  public interface IMyService : IDependency
  {
      [OperationContract]
      string GetTest();
  }
  
  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  class MyService : IMyService
  {
      public string GetTest()
      {
          return "test";
      }
  }
  </code></pre>
  
  <p>I couldn't get the service working by just modifying the module's web.config. I get the following error </p>
  
  <pre><code>ASP.NET routing integration feature requires ASP.NET compatibility.
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Orchard Root Web.Config</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;
      &lt;!-- ... --&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Routes.cs</p>
  
  <pre><code>public IEnumerable&lt;RouteDescriptor&gt; GetRoutes() {
      return new[] {
                       new RouteDescriptor {   Priority = 20,
                                               Route = new ServiceRoute(
                                                   "Services",
                                                   new OrchardServiceHostFactory(),
                                                   typeof(IMyService))
  
                       }
                   };
  }
  </code></pre>
  
  <p>This works, the key here is that you must call typeof on the object that is referencing IDependency, WorkContextModule.IsClosingTypeOf cant handle the object that consumes the dependancy, it must take the Interface that it is directly called by.</p>