繁体   English   中英

使用服务时出错:“找不到引用合同的默认端点元素”

[英]Error when using service: “Could not find default endpoint element that references contract”

我试图通过修改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.

这是使用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>

这是仍在使用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>

配置有问题吗,或者这是由于我切换到的HTTP绑定所施加的某些限制所致?

您的客户端配置文件很可能指定两个端点。 旧的TCP端点和新的HTTP端点。 在代码中声明客户端时,要么在客户端配置文件中删除旧的TCP终结点,要么使用构造函数(构造函数将终结点的名称作为字符串,例如new YourClient("NameOfWsHttpBinding"); )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM