For quite a while we have had a service hosted in IIS, and another library/application has been using the same service as a self hosted service.
The IIS service is hosted using http/https bindings and the self hosted service is hosted using a net named pipe binding.
Now somewhere in the IIS hosted application we started using the component that is self hosted (from another service). Due to the fact that the web.config is configured with http bindings but the self hosted one sends in a net.pipe:// url I get an error when trying to create a ServiceHost
instance.
The error i get:
Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding. Registered base address schemes are [net.pipe].
The code that is responsible for that error:
var host = new ServiceHost(typeof(Service1), new Uri("net.pipe://localhost/" + guid.ToString()));
My Web.config has the following section:
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="wsHttpBinding" name="endpoint1" contract="WcfServiceLibrary1.IService1" />
</service>
And if i remove that the self-hosting works fine but the IIS hosting does not work.
Now I am aware that I have at least two options.
- Add multiple Uri to the
ServiceHost()
constructor call - Implement the static
Configure
method on the service that has the self-hosting and call enableProtocol on required bindings (as described on msdn)
However I was wondering if there was some general way that I can get the desired result of having both hosting types in the same process without having to resort to one of the two above options.
For instance, is it possible to define protocols on a "global" level either via configuration or via code in the same manner as what is done via the static Configure
method or perhaps have the ServiceHost
ignore the configuration in some instances? (like when i create it my self).
I might very well be mixing concepts here but WCF is still a maze of configuration options to me.
A simple solution reproducing the error can be found here https://www.dropbox.com/s/e324vycbhkg5g5i/ReproduceWCFBindingIssue.zip?dl=0
Host the application and call the IAnotherService.DoStuff method on Service2.svc