2011-11-30 49 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配置文件参考。

相关问题