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:
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:
<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:
<services>
<service name="Test.UserServ" behaviorConfiguration="TCPBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/Users"/>
</baseAddresses>
</hos开发者_StackOverflow中文版t>
<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?
Most likely your client config file specifies two endpoints. Both the old TCP endpoint and your new HTTP endpoint. 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");
).
精彩评论