2011-11-30 43 views
0

可能重複:
WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'WCF:找不到默認的終結點元素引用合同

我的客戶端代碼如下:

public virtual bool CanExecute(Move movement) 
     { 
      using (MediatorServiceContractClient mediatorProxy = new MediatorServiceContractClient()) 
      { 
       return mediatorProxy.CanMove(movement); 
      } 
     } 

出現的錯誤在MediatorServiceContractClient的構造函數中。

該合同是如下:

namespace GameServices 
{ 
    [ServiceContract] 
    public interface IMediatorServiceContract 
    { 
     [OperationContract] 
     bool CanMove(Move move); 
    } 
} 

我有具有以下配置數據一個GameServices庫:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_IMediatorServiceContract" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" 
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:8732/GameServices/Mediator/" 
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMediatorServiceContract" 
      contract="GameViewModel.MediatorServiceReference.IMediatorServiceContract" 
      name="WSHttpBinding_IMediatorServiceContract"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
    </client> 
    <services> 
     <service name="GameServices.MediatorService"> 
     <endpoint address="" binding="wsHttpBinding" contract="GameServices.IMediatorServiceContract"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/GameServices/Mediator/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, 
      set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="True"/> 
      <!-- To receive exception details in faults for debugging purposes, 
      set the value below to true. Set to false before deployment 
      to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

</configuration> 

我然後有一個具有以下配置的數據的視圖模型庫:

enter code here`<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    </configSections> 
    <system.serviceModel> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="WSHttpBinding_IMediatorServiceContract" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
        allowCookies="false"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" 
         enabled="false" /> 
        <security mode="Message"> 
         <transport clientCredentialType="Windows" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" 
          algorithmSuite="Default" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:8732/GameServices/Mediator/" 
       binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMediatorServiceContract2" 
       contract="GameViewModel.MediatorServiceReference.IMediatorServiceContract" 
       name="WSHttpBinding_IMediatorServiceContract"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

我還在運行時收到以下錯誤消息: 找不到在ServiceModel客戶端配置部分中引用合同「MediatorServiceReference.IMediatorServiceContract」的默認端點元素。這可能是因爲沒有找到適用於您的應用程序的配置文件,或者因爲在客戶端元素中找不到匹配此合同的端點元素。

我查看了關於這個常見問題的所有意見和反饋。但對我來說,問題依然存在,我被卡住了。我錯過了什麼?爲什麼這很複雜?

+1

發佈使用服務(即客戶端)的代碼。我猜第一個配置文件是用於服務的(但爲什麼它有一個客戶端端點?),第二個用於客戶端連接。 –

+0

是的。第一個配置數據是服務器端。配置數據的第二篇文章是客戶端。 –

+0

客戶端端點是在服務器端配置文件中自動生成的。 –

回答

0

一些事情(我沒有用過WPF,但是我用WCF做了很多,所以如果這是WPF特定的問題,這可能不適用)。

您看到的錯誤消息表示無法找到MediatorServiceReference.IMediatorServiceContract的端點。如果您查看服務配置,您的端點合同是GameServices.IMediatorServiceContract;這很可能是導致錯誤的原因。修復引用的合同,你應該很好去。其次,將using塊與代理一起使用被認爲是不好的做法。最好簡單地打開代理,撥打電話,關閉(或根據需要中止)頻道。有關詳細說明,請參閱Avoiding Problems with the Using Statement

+0

您好蒂姆,我更新了客戶端是GameServices.IMediatorServiceContract。但是,我仍然收到相同的錯誤。我將非常樂意向您發送源代碼... –

1

看起來客戶端配置的端點中的契約應該是GameServices.IMediatorServiceContract,而不是GameViewModel.MediatorServiceReference.IMediatorServiceContract,假設您粘貼的接口的代碼是客戶端實際使用的。

+0

我更新了僅有GameServices.IMediatorServiceContract的客戶端配置。但是,我仍然收到同樣的錯誤。我很樂意將您的源代碼發送給您... –

+0

我仍然卡住了。我真誠地認爲這是VS2010中的一個錯誤。我還觀看並重新配置了客戶端。我觀看了以下視頻:http://channel9.msdn.com/shows/Endpoint/Endpoint-Screencasts-Creating-Your-First-WCF-Client/ –

0

Mike Gledhill適合WPF應用程序。我的源應用程序配置文件不在客戶端可執行項目中,而是在我的viewmodel項目中(仍在客戶端)。

因此,我簡單地在我的可執行項目的viewmodel項目中添加了一個鏈接到我的應用程序配置。

它終於在大概12個小時的挫折後工作。

所以心智記錄:即使它不包含執行調用的cs文件,可執行項目也必須有一個APP配置文件參考。

相關問題