WCF service with two binding types for two different clients
H开发者_C百科ow can I expose a WCF service so that one client using wsHttp bindings and another client using netTcp bindings can both use the service?
It's all a configuration thing - when you define your service, you just go about and define two endpoints - one for wsHttpBinding
, the other for netTcpBinding
. It's as simple as that!
<system.serviceModel>
<services>
<service name="YourNamespace.MyService">
<endpoint
address="ws"
binding="wsHttpBinding"
contract="YourNamespace.IMyService" />
<endpoint
address="net.tcp://localhost:8787/MyService"
binding="netTcpBinding"
contract="YourNamespace.IMyService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8282/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Now you have your service exposing two endpoints:
- one using the
wsHttpBinding
athttp://localhost:8282/ws
- one using the
netTcpBinding
attcp://localhost:8787/MyService
Both endpoints are for the same service, for the same service contract, e.g. offer the same functionality and service methods.
Each service endpoint in WCF must define the ABC of WCF:
- [A]ddress - where can the service be reached/called?
- [B]inding - how can the service be called (protocol, settings, security etc.)?
- [C]ontract - what does the service offer at this address, what methods are exposed?
In short, you can do it simply through configuration!
Have you seen this tutorial? Do check this out.
Its an excellent tutorial with screen images of the entire basic process of configuring a sample service with multiple end points using the Microsoft Service Configuration Editor.
精彩评论