[英]Error when using service: “Could not find default endpoint element that references contract”
I'm trying to switch my WCF service from TCP bindings to HTTP bindings by modifying app.config
, but when I try consuming the WCF service from a test console application, I get this error: 我试图通过修改
app.config
将WCF服务从TCP绑定切换到HTTP绑定,但是当我尝试从测试控制台应用程序使用WCF服务时,出现此错误:
Could not find default endpoint element that references contract 'ServiceReference1.IUsers' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Here's the newer app.config using HTTP bindings that gives me the error above: 这是使用HTTP绑定的较新的app.config,它给了我上面的错误:
<services>
<service name="Test.UserServ" behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Users" />
</baseAddresses>
</host>
<endpoint
address=""
binding="webHttpBinding" behaviorConfiguration="EndpointBehavior"
contract="Test.IUsers" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
Here's the older working app.config that still uses TCP bindings: 这是仍在使用TCP绑定的较旧的可运行app.config:
<services>
<service name="Test.UserServ" behaviorConfiguration="TCPBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Users"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="netTcpBinding" bindingConfiguration="TCPConfiguration"
contract="Test.IUsers"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="TCPConfiguration">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="TCPBehavior">
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
Is there something wrong with the configuration or is this due to some limitation imposed by the HTTP bindings I've switched to? 配置有问题吗,或者这是由于我切换到的HTTP绑定所施加的某些限制所致?
Most likely your client config file specifies two endpoints. 您的客户端配置文件很可能指定两个端点。 Both the old TCP endpoint and your new HTTP endpoint.
旧的TCP端点和新的HTTP端点。 Either delete the old TCP endpoint in your client config file or use the constructor when declaring the client in your code (the constructor takes the name of an endpoint as a string, smth like
new YourClient("NameOfWsHttpBinding");
). 在代码中声明客户端时,要么在客户端配置文件中删除旧的TCP终结点,要么使用构造函数(构造函数将终结点的名称作为字符串,例如
new YourClient("NameOfWsHttpBinding");
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.