title: Explicitly calling a service constructor when hosting a WCF web service on IIS
body: <p>I want to host a WCF service of mine on Microsoft IIS (IIS hosting).</p>
  
  <p>To do this, I created my service:</p>
  
  <pre><code>// The service
  public class MyService : IMyService {
      // Ctors
      public MyService() {
          // Def ctor: I don't want to call it
      }
      public MyService(...) : this() {
          // Parametric ctor, I want to call it!
      }
     ...
  }
  
  // The contract
  [ServiceContract]
  public interface IMyService {
      ...
  }
  </code></pre>
  
  <p>I created a svc file (a good approach to give a base address to my service):</p>
  
  <pre><code>&lt;@ServiceHost Service="MyService" @&gt;
  </code></pre>
  
  <p>But doing so, when hosting my service (simply creating a virtual directory in IIS pointing to the folder where my application resides, the project directory usually), IIS will call the default constructor.</p>
  
  <p>How do I make IIS call a different constructor?</p>
  
  <p>PS: I know that it is possible to specify a <code>HostServiceFactory</code>. Is it something I should use here? It gives me back the factory and a host. For the host, I cannot act on the host passed parameters. However, how do I solve this problem?</p>
  
  <p>NOTE: I understood that many solutions are based on <a href="http://en.wikipedia.org/wiki/Inversion_of_control" rel="nofollow">Inversion of control</a> (IoC) and several IoC frameworks like <a href="http://unity.codeplex.com/" rel="nofollow">Unity</a>, <a href="http://en.wikipedia.org/wiki/Inversion_of_control" rel="nofollow">Castle Project</a> and <a href="http://en.wikipedia.org/wiki/Spring_Framework" rel="nofollow">Spring.NET</a>. However I would not really use them at all. Can <a href="http://en.wikipedia.org/wiki/Windows_Communication_Foundation" rel="nofollow">WCF</a> make this on its own? I cannot accept that WCF cannot let a programmer host a service by constructing it in the appropriate manner...</p>