在所有脚本中找不到默认端点元素错误
本文关键字:默认 端点 元素 错误 找不到 脚本 | 更新日期: 2023-09-27 18:37:27
我想连接到 WCF 服务。 服务引用驻留在类库中。通过将 App.config 添加到单元测试项目,我成功地连接到 MSTEST 单元测试中的服务。 我无法成功连接到应用程序中的服务。 我找到了应用程序的配置文件。 我能够编辑文件,并确认我可以通过以下途径访问添加到配置中的密钥
<add key="testKey"
但是,当我尝试在应用程序中连接时,我收到错误
在 ServiceModel 客户端配置部分中找不到引用协定"ContractName.Service"的默认终结点元素。 这可能是因为在客户端元素中找不到与此协定匹配的终结点元素。
我添加了该部分
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPinGenerator" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://somewhere"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPinGenerator"
contract="CompanyNamePinGenerator.IPinGenerator" name="BasicHttpBinding_IPinGenerator" />
</client>
</system.serviceModel>
然而,它并不能解决问题。 我还尝试将命名空间添加到contract=""
和生成的代码属性中
[System.ServiceModel.ServiceContractAttribute(ConfigurationName=
任何想法如何解决这个问题?
出现此问题的原因是客户端配置中没有任何与名称 ContractName.Service
匹配的终结点。
我所看到的只是你只有一个端点,具有不同的合约CompanyNamePinGenerator.IPinGenerator
.
位于代理文件中的服务类或接口引用ContractName.Service
,而配置中缺少该。
你必须确保几件事:
- 将生成的代理更新为最新版本
- 确保客户端配置包含服务所需的所有终结点。
通常,当我遇到此类问题时,我会打开VS命令提示符运行svcutil.exe并从生成的文件中复制代理代码和客户端配置。