.net WCF客户端找不到配置文件

.net WCF客户端找不到配置文件,.net,wcf,app-config,.net,Wcf,App Config,考虑以下情况: 名为preorderservice的WCF主机 名为server.exe和engine.dll的控制台exe engine.dll具有到preorderservice的有效代理 system.servicemodel已添加到server.exe.config <system.serviceModel> <bindings> <netTcpBinding> <binding name="n

考虑以下情况:

名为preorderservice的WCF主机

名为server.exe和engine.dll的控制台exe

engine.dll具有到preorderservice的有效代理

system.servicemodel已添加到server.exe.config

  <system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="netTcppreorderservice" openTimeout="00:01:00" />
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://localhost:9000/ServicesHost/preorderservice/preorderservice"
            binding="netTcpBinding" bindingConfiguration="netTcppreorderservice"
            contract="preorderservice.Ipreorderservice" name="netTcppreorderservice">
        </endpoint>
    </client>
  </system.serviceModel>  
但是例外

System.InvalidOperationException:在ServiceModel客户端配置节中找不到名为“netTcppreorderservice”和约定为“preorderservice.Ipreorderservice”的终结点元素 这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此名称匹配的端点元素

但是名称是正确的,并且在该文件中找到了其他配置设置,我不知道如何解决这个问题

当从配置中读取Uri时,键入WCF代理创建,这样就可以找到配置了

            EndpointAddress ep = new EndpointAddress(ConfigurationManager.AppSettings["preorderservice"]); 

            Ipreorderservice proxy = ChannelFactory<Ipreorderservice>.CreateChannel(new NetTcpBinding(), ep);
EndpointAddress ep=新的EndpointAddress(ConfigurationManager.AppSettings[“preorderservice”]);
Ipreorderservice proxy=ChannelFactory.CreateChannel(新的NetTcpBinding(),ep);
通过请求,在整个配置中编辑,一些应用设置被剪掉。它也使用AppFabric,它确实可以工作,而且也是一个WCF服务

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,&#xD;&#xA;            Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, &#xD;&#xA;            Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere" />
  </configSections>
  <dataCacheClient maxConnectionsToServer="6">
    <localCache isEnabled="true" sync="TimeoutBased" ttlValue="300" objectCount="10000"/>
    <hosts>
      <host name="w2k8cache" cachePort="22233" />
    </hosts>
  </dataCacheClient>
  <appSettings>
    <add key="Local.Labs" value="50,51" />
  </appSettings>
  <system.diagnostics>
    <switches>
      <add name="Engine" value="4" />
    </switches>
  </system.diagnostics>
  <system.runtime.remoting>
    <application>
      <channels>
        <channel ref="tcp" port="1966" clientConnectionLimit="32">
          <serverProviders>
            <formatter ref="binary" />
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="netTcppreorderservice" openTimeout="00:01:00" />
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://localhost:9000/ServicesHost/preorderservice/preorderservice"
            binding="netTcpBinding" bindingConfiguration="netTcpRopsPreorderService"
            contract="preOrderservice.Ipreorderservice" name="netTcppreorderservice">
        </endpoint>
    </client>
  </system.serviceModel>
</configuration>

如果我的内存良好,您的配置必须位于engine.dll.config中。
我很确定,如果您想使用server.exe.config,您可以定义自己的配置文件。

您是手动输入的还是在server.exe项目中使用了WCF配置工具,您是否有对System.Configuration.dll和System.ServiceModel.dll的引用?它是生成的,并且两个引用都存在。我可以确认server.exe是一个静态引用engine.dll的.NET控制台应用程序吗?另外,您介意发布整个server.exe.config吗?
<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,&#xD;&#xA;            Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, &#xD;&#xA;            Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere" />
  </configSections>
  <dataCacheClient maxConnectionsToServer="6">
    <localCache isEnabled="true" sync="TimeoutBased" ttlValue="300" objectCount="10000"/>
    <hosts>
      <host name="w2k8cache" cachePort="22233" />
    </hosts>
  </dataCacheClient>
  <appSettings>
    <add key="Local.Labs" value="50,51" />
  </appSettings>
  <system.diagnostics>
    <switches>
      <add name="Engine" value="4" />
    </switches>
  </system.diagnostics>
  <system.runtime.remoting>
    <application>
      <channels>
        <channel ref="tcp" port="1966" clientConnectionLimit="32">
          <serverProviders>
            <formatter ref="binary" />
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="netTcppreorderservice" openTimeout="00:01:00" />
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://localhost:9000/ServicesHost/preorderservice/preorderservice"
            binding="netTcpBinding" bindingConfiguration="netTcpRopsPreorderService"
            contract="preOrderservice.Ipreorderservice" name="netTcppreorderservice">
        </endpoint>
    </client>
  </system.serviceModel>
</configuration>