I am trying to create self-hosted System.ServiceModel.Web.WebServiceHost
(.NET 4), however I am running into an issue with the constructor. There are three options:
WebServiceHost()
a parameterless constructor that seems pointless, as there's no way to specify the type of the service, or even the contract. Reflecting on it, it doesn't do anything- just an empty default constructor that doesn't call base.WebServiceHost(object singletonInstance, params Uri[] baseAddresses)
I don't want a singleton instance, as this is aInstanceContextMode.PerCall
class.WebServiceHost(System.Type serviceType, params Uri[] baseAddresses)
The type I want to instantiate as a service doesn't have a parameterless constructor (which is a requirement of this method). I'm using NInject to push the parameters into the constructor. However, I'm trying to run this as a self-hosted test, so I want to avoid DI.
Are there any options along these lines, or will I have to not self-host?
To support service classes without parameter-less constructors you need to use an
IInstanceProvider
implementation which knows how to create the service class. The code below shows one with theWebServiceHost
, and you can find more about instance providers at http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/31/wcf-extensibility-iinstanceprovider.aspx.