简体   繁体   English

WCF在web.config中设置了不同的区域性终结点

[英]WCF set different culture endpoints in web.config

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. 我有一个WCF服务,需要针对几种不同的文化进行本地化,主要提供不同语言的错误和响应消息。 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: 例如,我将具有以下不同的URL:

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: 我认为,为了使这种方法可行,我需要能够在web.config中按照以下方式进行配置:

<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? 还是有更好的方法呢?

There is a similar discussion on having different WCF endpoints for localization here: 这里有关于使用不同的WCF端点进行本地化的类似讨论:

http://geekswithblogs.net/dlanorok/archive/2007/07/18/Dynamic-Configuration-for-WCF-Service-Base-Address.aspx 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... 我的问题更笼统...是否有一种方法可以基于OperationContext之类的方法动态选择端点...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM