Can a single WCF service offer multiple interfaces, and if so how would you express this in app.config
?
I mean one services offering several Interfaces on one endpoint.
WCF allow us to give multiple base addresses for each type of protocol. And at the run time corresponding endpoint will take the base address. So you can expose IService1 on multiple EndPoint with more than one binding as below.
C# allows the implementation of multiple interfaces with the same method name.
As demonstrated in the Multiple Endpoints sample, a service can host multiple endpoints, each with different addresses and possibly also different bindings. This sample shows that it is possible to host multiple endpoints at the same address.
First you need to be clear what a service is. Do you mean a single endpoint, or multiple endpoints in the same host?
Assuming you mean a single endpoint, then yes, but with a little work. An endpoint can only implement a single interface; so what you need to do is combine all the interfaces you want to implement into a single interface
public interface IMyInterface : IInterface1, IInterface2
and then implement them all inside your implementation class. What you cannot do is have multiple interfaces and multiple implementations magically merge into a single endpoint.
The following looks closer to the original goal and doesn't involve one large interface...
Multiple Endpoints at a Single ListenUri: http://msdn.microsoft.com/en-us/library/aa395210.aspx
The sample linked to above explains that it's possible to have multiple endpoints registered at the same physical address (listenUri), each implementing a different interface (contract), e.g.:
<endpoint address="urn:Stuff" binding="wsHttpBinding" contract="Microsoft.ServiceModel.Samples.ICalculator" listenUri="http://localhost/servicemodelsamples/service.svc" /> <endpoint address="urn:Stuff" binding="wsHttpBinding" contract="Microsoft.ServiceModel.Samples.IEcho" listenUri="http://localhost/servicemodelsamples/service.svc" /> <endpoint address="urn:OtherEcho" binding="wsHttpBinding" contract="Microsoft.ServiceModel.Samples.IEcho" listenUri="http://localhost/servicemodelsamples/service.svc" />
This is possible because incoming messages are routed to the appropriate endpoint based on a combination of address and contract filters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With