Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF在web.config中设置不同的区域性终结点_Wcf_Localization_Endpointbehavior - Fatal编程技术网

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

WCF在web.config中设置不同的区域性终结点,wcf,localization,endpointbehavior,Wcf,Localization,Endpointbehavior,我有一个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 <s

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

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
<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端点进行本地化的类似讨论:

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

我的问题更一般…有没有一种方法可以根据OperationContext之类的内容动态选择端点