[英]Could not find endpoint element with name '' and contract '' in the ServiceModel client configuration section
[英]Could not find endpoint element with name and contract
我添加了对具有两个端点的WCF服务的引用。 在添加服务时,以下内容将添加到Config文件中:
<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");
但是,我收到运行时错误 - “找不到名称为'ABCServiceV2'的端点元素,并在ServiceModel客户端配置部分中收缩'ABCService.IService'。这可能是因为找不到您的应用程序的配置文件,或者因为没有匹配此名称的端点元素可以在客户端元素中找到。“
如果我使用ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV1");
一切正常。 但是当使用ABCServiceV2时,它正在尝试寻找Contract - ABCService.IService - 它应该在什么时候寻找 - ABCService.IService1。
我如何让它寻找正确的合同?
如果您添加了对不同服务的第二个引用(ABCServiceV2),那么我相信这将为ABCServiceV2生成第二个服务类。 这两个类将实现单独的合同(ABCService.IService和ABCService.IService1),因此您将无法交换端点。
我相信你应该能够初始化你的两个服务端点,如下所示:
ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV1");
ABCService.Service1Client ABCClient1 = new Service1Client("ABCServiceV2");
虽然这篇文章很老并且回答了,但答案对我来说并没有帮助。 我的问题是我使用svcutil.exe工具生成了服务客户端,但根本没有指定任何命名空间; 因此,默认情况下,合同命名空间名称是作为架构文档的目标命名空间生成的,是完全混乱。
另一方面,我试图使用服务引用添加到项目时生成的配置文件。 此文件中的合同命名空间是ServiceReference1(默认情况下)或您想要的任何其他名称,完美风暴! 但我所要做的就是从<endpoint>
的contract属性中删除FQN中的命名空间部分,并且CLR可以看到合同。
希望这能帮到别人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.