无法在ServiceModel客户端配置部分中找到引用合同的默认端点元素

时间:2014-07-02 11:53:01

标签: wcf iis

我正在尝试开发WCF服务并在IIS中托管它。但是当我尝试使用服务时,我收到了这个错误。

  

无法找到引用合同的默认端点元素' ServiceReference1.IService1'在ServiceModel客户端配置部分中。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

我已经使用WCF测试客户端测试了WCF服务,并且我能够成功调用它。

但是当我消费它时,同样不起作用。请帮助我解决这个问题。

web.config我在WCF中使用过:

<!--WCF web config-->
    <system.serviceModel>    
        <services>    
          <service name="ProductServiceLibrary.RuelaService">    
            <endpoint address="" binding="wsHttpBinding" contract="RuelaService.IService1">    
              <identity>    
                <dns value="localhost" />    
              </identity>    
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>    
        </services>    

        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>

当我使用WCF服务时,我使用了这个app.config

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="BasicHttpBinding_IService1" />
      </basicHttpBinding>
   </bindings>
   <client>
       <!--URL where I have hosted my WCF http://localhost:9999/Service1.svc-->
       <endpoint name="BasicHttpBinding_IService1" 
           address="http://localhost:9999/Service1.svc" 
           binding="basicHttpBinding"
           bindingConfiguration="BasicHttpBinding_IService1"  
           contract="ServiceReference1.IService1" />
   </client>
</system.serviceModel>


  [1]: http://i.stack.imgur.com/djQoN.png

1 个答案:

答案 0 :(得分:0)

该服务似乎暴露了与客户端配置不同的合同。

服务:

<endpoint address="" binding="wsHttpBinding" 
   contract="RuelaService.IService1">   

客户:

 <endpoint name="BasicHttpBinding_IService1" 
           address="http://localhost:9999/Service1.svc" 
           binding="basicHttpBinding"
           bindingConfiguration="BasicHttpBinding_IService1"  
           contract="ServiceReference1.IService1" />

所以某处不匹配。