WCF set different culture endpoints in web.config

1.3k Views Asked by At

I've got a WCF service that I need to localise for a few different cultures, mainly providing error and response messages in different languages. Rather than relying on parsing something from the request header I'm leaning towards providing different endpoints for each of the support cultures. For example I would have different URLs along the lines of:

http://server/mycompany-rest/v1.0/service.svc
http://server/mycompany-rest/v1.0/service.svc/fr
http://server/mycompany-rest/v1.0/service.svc/cn

I think For this approach to be feasible I would need to be able to configure it in my web.config along the lines of:

<system.serviceModel>
  <services>
    <service name="MyCompany.Service.Rest.SomeService">
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      <endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="MyCompany.Service.Rest.ISomeService"/>
      <endpoint address="fr" binding="webHttpBinding" behaviorConfiguration="WebBehaviorFrench" contract="MyCompany.Service.Rest.ISomeService"/>
      <endpoint address="cn" binding="webHttpBinding" behaviorConfiguration="WebBehaviorChinese" contract="MyCompany.Service.Rest.ISomeService"/>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="WebBehavior">
        <webHttp/>
      </behavior>
      <behavior name="WebBehaviorFrench">
        <webHttp/>
        <culture value="fr" />
      </behavior>
      <behavior name="WebBehaviorChinese">
        <webHttp/>
        <culture value="zh-cn" />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

I realise there is no culture element for an endpoint behaviour but is this sort of approach going to be feasible with a custom behaviour? Or alternatively is there a better way to do it?

1

There are 1 best solutions below

0
On

There is a similar discussion on having different WCF endpoints for localization here:

http://geekswithblogs.net/dlanorok/archive/2007/07/18/Dynamic-Configuration-for-WCF-Service-Base-Address.aspx

It seems this is just about server configuration...the client still has to explicitly choose an endpoint named after the culture.

My question is more general...is there a way to dynamically choose an endpoint based of something like OperationContext...