我已经添加了一个引用到一个具有两个终点的 WCF 服务。在添加服务时,以下内容会添加到配置文件中:
<client>
<endpoint name="ABCServiceV1" address="http://staging.ABCwebservices.com/ABC/Service.svc"
binding="basicHttpBinding" bindingConfiguration="ABCServiceV1"
contract="ABCService.IService" />
<endpoint name="ABCServiceV2" address="http://staging.ABCwebservices.com/ABC/Service.svc/20"
binding="basicHttpBinding" bindingConfiguration="ABCServiceV2"
contract="ABCService.IService1" />
</client>
创建客户端的代码如下:
ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV2");
然而,我遇到了一个运行时错误 - “在ServiceModel客户端配置部分中找不到名称为'ABCServiceV2'和合同为'ABCService.IService'的终结点元素。这可能是因为找不到应用程序的配置文件,或者因为未找到与此名称匹配的终结点元素。” 如果我使用
ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV1");
,那么一切正常。但是当使用ABCServiceV2时,它会尝试查找合同 - ABCService.IService - 而应该查找 - ABCService.IService1。 我该如何使它查找正确的合同?