[英]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.