簡體   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