I want to host a WCF service of mine on Microsoft IIS (IIS hosting).
To do this, I created my service:
// 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 {
...
}
I created a svc file (a good approach to give a base address to my service):
<@ServiceHost Service="MyService" @>
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.
How do I make IIS call a different constructor?
PS: I know that it is possible to specify a HostServiceFactory
. 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?
NOTE: I understood that many solutions are based on Inversion of control (IoC) and several IoC frameworks like Unity, Castle Project and Spring.NET. However I would not really use them at all. Can WCF make this on its own? I cannot accept that WCF cannot let a programmer host a service by constructing it in the appropriate manner...