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

时间:2016-12-28 15:15:31

标签: c# .net wcf wcf-binding endpoint

我创建了一个WCF服务,而Web.Config文件的设置如下。

 <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" sendTimeout="10:00:00" openTimeout="10:00:00">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<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>
<services>
  <service name="Axis.OptimizationService.RMSCalculationService">
    <endpoint address="" binding="basicHttpBinding" contract="Axis.RMS.Optimization.Contracts.IRMSCalculationService"></endpoint>
  </service>
</services>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"  minFreeMemoryPercentageToActivateService="0"/>

在我的ClassLibrary项目中,我创建了名为CatpricingService的Servcie引用,app.config文件如下所示。

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IRMSCalculationService" closeTimeout="00:30:00"
        openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="01:00:00"
        maxBufferPoolSize="0" maxReceivedMessageSize="2147483647"
        useDefaultWebProxy="true" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:2200/RMSCalculationService.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRMSCalculationService"
    contract="CatPricingService.IRMSCalculationService"  name="BasicHttpBinding_IRMSCalculationService" />
</client>

我不确定我在这里做错了什么。我这样做了好几次。我无法弄清楚错误是什么。对我来说,所有设置都是正确的 我收到了这个错误。

Could not find default endpoint element that references contract 'CatPricingService.IRMSCalculationService' 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.

我在Stackoverflow上提到了其他问题.....我对此感到疯狂。 任何人都可以弄清楚我的设置有什么问题吗?

这里我的ClassLibrary项目使用外部程序excel.exe运行。 (项目属性,调试选项卡,选择“启动外部程序”并将值赋予 C:\ Program Files \ Microsoft Office \ Office14 \ EXCEL.EXE

由于

2 个答案:

答案 0 :(得分:4)

您需要将配置从app.config项目中的ClassLibrary移动到主项目的app.config(例如,WPF应用程序)。可能是引用您ClassLibrary的项目。

程序执行时,将仅使用主项目中的app.config

<强>更新

在这种情况下,我认为您需要以编程方式创建客户端类,不依赖于app.config,如下所示:

var binding = new BasicHttpBinding();
var endPointAddress = new EndpointAddress("http://localhost:2200/RMSCalculationService.svc");
var client = new YourGeneratedClientClass(binding, endPointAddress);

答案 1 :(得分:0)

最后通过将app.config文件重命名为Excel.exe.config到此文件夹C:\ Program Files \ Microsoft Office \ Office14 \来解决它。由于应用程序正在运行,它正在该位置查找Config文件。