Web services 尝试从app.config文件创建WCF绑定时出现异常

Web services 尝试从app.config文件创建WCF绑定时出现异常,web-services,wcf,app-config,wcf-binding,wcf-client,Web Services,Wcf,App Config,Wcf Binding,Wcf Client,您好,我有一个c#客户端应用程序试图连接到WCF web服务。绑定的配置位于客户端的app.config文件中 当我调用以恢复web服务(这是一个https连接)时,我得到以下错误 例外情况详情: System.InvalidOperationException: Could not find default endpoint element that references contract 'TcWcfServices.ITcWcfService' in the ServiceModel cl

您好,我有一个c#客户端应用程序试图连接到WCF web服务。绑定的配置位于客户端的app.config文件中

当我调用以恢复web服务(这是一个https连接)时,我得到以下错误

例外情况详情:

System.InvalidOperationException: Could not find default endpoint element that references contract 'TcWcfServices.ITcWcfService' 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.
   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
   at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()
   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
   at xx.Int.Biz.Services.TMOScheduling.TcWcfServices.TcWcfServiceClient..ctor()
我的代码是简单的调用

   if (_wcfClient == null)
        _wcfClient = new TcWcfServiceClient();
在我的TMOSAcheduling.exe.config文件中,我有这个代码段要尝试并绑定到WCF服务

   <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpsBinding_ITcWcfService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="33554432" maxBufferPoolSize="524288" maxReceivedMessageSize="33554432"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
          <readerQuotas maxDepth="999999999" maxStringContentLength="999999999"
            maxArrayLength="999999999" maxBytesPerRead="999999999" maxNameTableCharCount="999999999" />
          <security mode="Transport">
            <transport clientCredentialType="None"
                       proxyCredentialType="None"
                       realm=""/>
            <message clientCredentialType="UserName"
                     algorithmSuite="Default"/>
          </security>
        </binding>

      </basicHttpBinding>
    </bindings>

    <!-- If Environment is HTTPS then use below client and comment out HTTP Client-->
    <!-- HTTPS Client -->

    <client>
      <endpoint address="https://xyz.externalhttpsAddredd.net/TcWcfServices/TcWcfServices.svc"
                behaviorConfiguration="TcWcfServicesBehavior"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpsBinding_ITcWcfService"
                contract="TcWfcServices.ITcWcfService"
                name="BasicHttpsBinding_ITcWcfService" />
    </client>

    <behaviors>
      <endpointBehaviors>
        <behavior name="TcWcfServicesBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

我想知道是否有人能给我一些建议,告诉我问题是什么,或者我如何添加HTTPS绑定,这样我就可以实例化和调用服务了

这个配置文件必须是“手工生成”的,因为我是针对一个名称相同的服务开发的,该服务不是HTTPS,也位于我的localhost开发webservice站点上

此外,此客户端应用程序无法在我的开发机器上运行,因为我无法从开发机器访问服务器URL

谢谢!我是在一个关键的时候得到这一点的实施,并尝试了一切,我可以想到类似的结果

编辑这里是第二个配置文件

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpsBinding_ITcWcfService"
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
       allowCookies="false" bypassProxyOnLocal="false"      hostNameComparisonMode="StrongWildcard"
  maxBufferSize="33554432" maxBufferPoolSize="524288" maxReceivedMessageSize="33554432"
  messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
  useDefaultWebProxy="true">
      <readerQuotas maxDepth="999999999" maxStringContentLength="999999999"
        maxArrayLength="999999999" maxBytesPerRead="999999999" maxNameTableCharCount="999999999" />
      <security mode="Transport">
        <transport clientCredentialType="None"
                   proxyCredentialType="None"
                   realm=""/>
        <message clientCredentialType="UserName"
                 algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<client>
  <endpoint address="https://xxxxxx.testexternal.net/TcWcfServices/TcWcfServices.svc"
            behaviorConfiguration="TcWcfServicesBehavior"
            binding="basicHttpBinding"             
            contract="TcWfcServices.ITcWcfService" />
</client>
<behaviors>
  <endpointBehaviors>
    <behavior name="TcWcfServicesBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </endpointBehaviors>
</behaviors>

第二次编辑。此操作有效,但由于https错误而出现证书错误
问题在于您的元素定义了一个name属性,因此您需要将其删除以使其成为该协定的“默认端点”,或者在客户端代理对象的构造函数中手动指定端点名称

可选的字符串属性。此属性唯一地标识 给定合同的端点。您可以为一个应用程序定义多个客户端 给定的合同类型。每个定义都必须用一个 唯一的配置名称如果省略此属性,则 相应端点用作与关联的默认端点 指定的合同类型。默认值为空字符串


答案最终是我最后一次编辑,但我也有一个证书问题(另一件事)。因此,我们也转而使用HTTP


Tomasr-你的建议至少有助于我指出一些我不知道的端点之类的事情。我能够验证我是否使用了正确的配置,这是我自己的猜测。

我从配置中删除了“name=“BasicHttpsBinding_ITcWcfService”,但仍然得到一个错误。它显示Message=”在ServiceModel客户端配置节中找不到引用约定“TcWcfServices.itcwccfservice”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在client元素中找不到与此约定匹配的元素。我在服务中的一些其他配置设置肯定是从同一个文件中读取的。我将包括我现在的文件,以防其他突出。我已经解决了我的问题后,改变了一些事情。我们最终安装了一个我不需要HTTPS的内部服务器。我将发布我的配置文件最终是什么
  Second edit.  This worked but had certificate errors due to the https

  <system.serviceModel>
     <bindings>
       <basicHttpBinding>
          <binding name="BasicHttpBinding_ITcWcfService"
            closeTimeout="00:01:00"
            openTimeout="00:01:00"
            receiveTimeout="00:10:00"
            sendTimeout="00:01:00"
            allowCookies="false"
           bypassProxyOnLocal="false"
            hostNameComparisonMode="StrongWildcard"
           maxBufferSize="65536"
            maxBufferPoolSize="524288"
           maxReceivedMessageSize="65536"
           messageEncoding="Text"
           textEncoding="utf-8"
           transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32"
        maxStringContentLength="8192"
        maxArrayLength="16384"
          maxBytesPerRead="4096"
        maxNameTableCharCount="16384" />
       <security mode="Transport">
           <transport clientCredentialType="None"
            proxyCredentialType="None"
            realm="" />
            <message clientCredentialType="UserName"
             algorithmSuite="Default" />
           </security>
          </binding>
       </basicHttpBinding>
     </bindings>
     <client>
       <endpoint address="https://txxxx.external.net/TcWcfServices/TcWcfServices.svc"
           binding="basicHttpBinding"
           bindingConfiguration="BasicHttpBinding_ITcWcfService"
           contract="TcWcfServices.ITcWcfService"
           name="BasicHttpBinding_ITcWcfService" />
     </client>
   </system.serviceModel>