繁体   English   中英

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

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

我有一个WCF服务,需要针对几种不同的文化进行本地化,主要提供不同语言的错误和响应消息。 我不是依靠从请求标头中解析某些内容,而是倾向于为每种支持区域性提供不同的终结点。 例如,我将具有以下不同的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

我认为,为了使这种方法可行,我需要能够在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>

我意识到端点行为没有文化因素,但是这种方法对于自定义行为是否可行? 还是有更好的方法呢?

这里有关于使用不同的WCF端点进行本地化的类似讨论:

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

似乎这只是关于服务器的配置...客户端仍然必须显式选择以区域性命名的终结点。

我的问题更笼统...是否有一种方法可以基于OperationContext之类的方法动态选择端点...

暂无
暂无

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

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