Posted by: reuben | March 14, 2008

Multiple Endpoints in WCF

Adding multiple end points in WCF is one of the coolest features this technology has to offer (ok, I know there’s a lot more interesting things about WCF other than just adding multiple end points….hopefully I’ll cover those at some point in the future.)

So say you have a client that requires the “wsHttpBinding”. Simple enough, in your web.config file, you need an entry like this:

<service behaviorConfiguration=MyService.MyServiceBehavior name=MyService>

  <host>

     <baseAddresses>

        <add baseAddress=http://localhost/MyService.svc />

     </baseAddresses>

  </host>

  <endpoint address=ws binding=wsHttpBinding contract=MyService.MyContracts.IMyService />

</service>

But now, say you have a new client that needs to consume your service through a Asp.net 2.0 web application and requires the “basicHttpBinding”. For this, you’ll need to expose a new binding that supports this feature. This is pretty straight forward too, and can be done in the following manner:

<service behaviorConfiguration=MyService.MyServiceBehavior name=MyService>

  <host>

     <baseAddresses>

        <add baseAddress=http://localhost/MyService.svc />

     </baseAddresses>

  </host>

  <endpoint address=ws binding=wsHttpBinding contract=MyService.MyContracts.IMyService />

  <endpoint address=basic binding=basicHttpBinding contract=MyService.MyContracts.IMyService />

</service>

In this case, both bindings are derived from the same interface (as shown above.) Finally, when you access this service using the WCFTestClient, you’ll notice both the endpoints being exposed. The clients can then run, wsdl.exe (for the asp.net 2.0 client) and svcutil.exe (for asp.net 3.0 or higher) and generate their proxies.


Leave a response

Your response:

Categories