【问题标题】:WCF client cannot find configuration fileWCF 客户端找不到配置文件
【发布时间】:2014-10-06 12:29:13
【问题描述】:

考虑以下情况:

名为 preorderservice 的 WCF 主机

一个名为 server.exe 的控制台 exe,带有 engine.dll

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>  

然后使用此端点配置名称创建客户端

proxy = new preorderserviceclient("netTcppreorderservice");

但例外

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

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

并在从配置中读取 Uri 时输入 WCF 代理创建工作,以便找到配置.....

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

            Ipreorderservice proxy = ChannelFactory<Ipreorderservice>.CreateChannel(new NetTcpBinding(), ep);

根据要求,在整个配置中进行了编辑,一些 AppSettings 被剪掉了。它也使用 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>

【问题讨论】:

  • 您是手动输入的还是使用了 WCF 配置工具?
  • 在你的Server.exe项目中,有没有引用System.Configuration.dll和System.ServiceModel.dll?
  • 它已生成并且两个引用都存在
  • 我可以确认 server.exe 是一个静态引用 engine.dll 的 .NET 控制台应用程序吗?您还介意发布整个 server.exe.config 吗?

标签: .net wcf app-config


【解决方案1】:

如果我的记忆力好的话,你的配置必须位于 engine.dll.config 中。 如果你想使用 server.exe.config,我很确定你可以定义自己的配置文件。

【讨论】:

    猜你喜欢
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2011-10-13
    • 2014-05-12
    相关资源
    最近更新 更多