我有一个 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>
我意识到端点行为没有文化元素,但是这种方法对于自定义行为是否可行?或者有没有更好的方法来做到这一点?