繁体   English   中英

[WCF Duplex] 在 ServiceModel 客户端配置部分找不到引用合同的端点元素

[英][WCF Duplex]Could not find endpoint element that references contract in the ServiceModel client configuration section

我有一个使用 wcf 双工 wsdualhttpbinding 运行的发布-订阅通知。 但是当我开始在客户端订阅时,我收到消息:“无法在 ServiceModel 客户端配置部分找到引用合同的端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为没有端点元素与此匹配合同可以在客户元素中找到”

App.config客户端

<?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.config,所以当运行项目时,VS 读取了 web.config并忽略其他项目中的所有 app.config。

所以这里的解决方案是我只是将 app.config 中的所有设置代码移动到 web.config

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM