views:

56

answers:

2

How can I expose a WCF service so that one client using wsHttp bindings and another client using netTcp bindings can both use the service?

A: 

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.

InSane
+3  A: 

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 at http://localhost:8282/ws
  • one using the netTcpBinding at tcp://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?
marc_s
You could also have specified a base address for nettcp, just for the sake of consistency.
Johann Blais
@Johann Blais: yes, you could definitely do that - that's entirely up to you. I just wanted to show both method - with base address (for http), and without specifying an explicit, complete address in the <endpoint> tag.
marc_s