我使用wcf duplex wsdualhttpbinding运行了一个发布-订阅通知。但当我开始在客户端订阅时,我得到了这样的信息:无法在ServiceModel客户端配置部分中找到引用契约的端点元素。这可能是因为没有找到您的应用程序的配置文件,或者因为在客户端元素">
中没有找到与此契约匹配的端点元素。应用程序。配置客户端
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IRecipeTemplateService" />
<binding name="Basic1" />
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://172.18.26.14/CentralService/Services/NotificationService.svc"
binding="wsDualHttpBinding" bindingConfiguration="Basic1"
contract="CentralNotificationService.INotificationService"
name="Basic1">
<identity>
<servicePrincipalName value="host/myclienthost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
web . config
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<connectionStrings>
<add name="RecipeDB" providerName="MySql.Data.MySqlClient"
connectionString="Server=localhost; Port=3306; Database=recipe_db; Uid=root; Pwd=root" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework"/>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.28.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<system.serviceModel>
<services>
<service behaviorConfiguration="mexBehavior" name="RecipeServer.Central.Service.Services.NotificationService">
<endpoint address="" binding="wsDualHttpBinding"
name="Basic" contract="RecipeServer.Central.Service.Interfaces.INotificationService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="mexdata" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="wsDualHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
客户端代码
InstanceContext site = new InstanceContext(new ServiceCallBack());
try
{
client = new NotificationServiceClient(site);
}
catch (Exception e) {
RecipeLogger.GetInstance.ErrorLog(e.Message);
RecipeLogger.GetInstance.ErrorLog(e.StackTrace);
}
WSDualHttpBinding binding = (WSDualHttpBinding)client.Endpoint.Binding;
RecipeLogger.GetInstance.DebugLog("2");
binding.ClientBaseAddress = new Uri("http://localhost:8000/myClient/");
string clientcallbackaddress = binding.ClientBaseAddress.AbsoluteUri;
RecipeLogger.GetInstance.DebugLog(String.Format("Client baseadd {0}", clientcallbackaddress));
clientcallbackaddress += Guid.NewGuid().ToString();
binding.ClientBaseAddress = new Uri(clientcallbackaddress);
RecipeLogger.GetInstance.DebugLog("Subscribe to central");
client.Subscribe();
client.Close();
在修复这个问题近一周后,我意识到我在一个解决方案中有多个项目,最初的项目是服务项目,它有一个web。因此,当运行项目时,VS读取web。在其他项目中忽略所有的app.config。
这里的解决方案是将app。config中的所有设置代码移到web。config