Label Cloud

Saturday, October 13, 2007

Providing multiple endpoints for the WCF service

I had to implement compression for an internal WCF service. A requirement however is to make sure that older version of the service is left as is. To achieve that we've added another endpoint to the an existing binding

Here's the original Configuration File for the server.

<services> <service name="Repositories.Clients" behaviorConfiguration="DebugBehavior"> <endpoint name="Clients" contract="IClients" binding="basicHttpBinding" /> </service> <services> <behaviors> <serviceBehaviors> <behavior name="DebugBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors>

The URL for the service is http://hostname/Clients.svc

Here's the new file

<services> <service name="Repositories.Clients" behaviorConfiguration="DebugBehavior"> <endpoint name="Clients" contract="IClients" binding="basicHttpBinding" /> <endpoint name="ClientsCompressed" contract="IClients" bindingConfiguration="compressedConfiguration" binding="customBinding" address="compressed"/> </service> <services> <bindings> <customBinding> <binding name="compressedConfiguration"> <compression compressionMode="GZip" compressionLevel="Normal"/> <httpTransport/> </binding> </customBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="DebugBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors>

The new URL for the service is http://hostname/Clients.svcc/compressed

The old service works just like before. But the new one requires compressed data. It is serviced by a completely separate binding and has independent configuration.

 


You can follow the same above example to specify multiple client endpoints as well. However, if multiple endpoints exist, the WCF Proxy has to be created by specifying an endpoint name.

 

localhost.Clients1Client client = new localhost.Clients1Client("compressed");

Technorati Tags: , ,


Share/Save/Bookmark

No comments: