[英]WCF 4.5 - multiple web services
我想使用位於2個不同主機上的2個WCF Web服務(第一個可在HTTPS中訪問,第二個可在HTTP中訪問)。 兩種方法都具有相同的方法,但是第一種方法在生產服務器上,而第二種方法在測試服務器上。
當我在Visual Studio 2012(速成版)中添加引用時,得到2個名稱空間; 目前,我發現使用這些服務的唯一方法是使用在這些命名空間中生成的接口和類。 根據配置項的不同,我只想使用一個Web服務,指示我是處於調試還是發布模式。 我該如何通過代碼做到這一點?
這是我的配置文件:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ILotWebContract">
<security mode="Transport" />
</binding>
<binding name="BasicHttpBinding_ILotWebContract1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxx/Services/WebService/LotWebService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILotWebContract"
contract="eMol.ILotWebContract" name="BasicHttpBinding_ILotWebContract" />
<endpoint address="http://yyy/Services/WebService/LotWebService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILotWebContract1"
contract="eMolTest.ILotWebContract" name="BasicHttpBinding_ILotWebContract1" />
</client>
</system.serviceModel>
我試圖更改端點的地址:
eMolTest.LotWebContractClient client = new eMolTest.LotWebContractClient();
client.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://xxx/Services/WebService/LotWebService.svc");
client.Endpoint.Binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.Transport);
但是運行客戶端時生成的異常表明客戶端與服務之間的鏈接可能不對應。
當我調用代理的構造函數時,我還嘗試指出端點的名稱:
eMolTest.LotWebContractClient client = new eMolTest.LotWebContractClient("BasicHttpBinding_ILotWebContract");
但是由於命名空間不同(合約的名稱包含命名空間的名稱,因此無法在配置文件中定義的終結點中找到),它仍然無法工作。
所以,如果有人有一個好主意...
謝謝 ! 克里斯
如果您具有完全相同的合同的兩個服務,則應在所有三個參與方之間共享該合同作為合同程序集 ,並使用ChannelFactory類自己創建代理。 這樣,您就不會有兩個服務引用,盡管它們表示相同的合同,但它們從編譯器的角度來看是不兼容的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.