![](/img/trans.png)
[英]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.