考虑以下情况:
名为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:找不到名称为'netTcppreorderservice'的端点元素,并在ServiceModel客户端配置部分中找到'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,
 Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, 
 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>
答案 0 :(得分:0)
如果我的内存良好,您的配置必须位于engine.dll.config中。 如果您想使用server.exe.config,我非常确定您可以定义自己的配置文件。