簡體   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