简体   繁体   English

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

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

I have a publish-subscribe notification running with wcf duplex wsdualhttpbinding.我有一个使用 wcf 双工 wsdualhttpbinding 运行的发布-订阅通知。 But when I started to subscribe in client side, I got the message: "Could not find endpoint element that references contract in the ServiceModel client configuration section.This might be because no configuration file was found for your application or because no endpoint element matching this contract could be found in the client element"但是当我开始在客户端订阅时,我收到消息:“无法在 ServiceModel 客户端配置部分找到引用合同的端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为没有端点元素与此匹配合同可以在客户元素中找到”

App.config client 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 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>

Code in client side客户端代码

            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();

After having fixed this issue for nearly a week, I realized that I have multiples project in a solution, and the initial project was service project, and it had a web.config, so when run the project, the VS read the web.config and ignored all app.config at others project.修复这个问题将近一周后,我意识到我在一个解决方案中有多个项目,最初的项目是服务项目,它有一个 web.config,所以当运行项目时,VS 读取了 web.config并忽略其他项目中的所有 app.config。

So the solution here is I just moved all settings code in app.config into web.config所以这里的解决方案是我只是将 app.config 中的所有设置代码移动到 web.config

暂无
暂无

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

相关问题 在ServiceModel客户端配置部分中找不到名称为``and contract&#39;&#39;的终结点元素 - Could not find endpoint element with name '' and contract '' in the ServiceModel client configuration section 在ServiceModel客户端配置部分中找不到引用合同的默认端点元素。 - Could not find default endpoint element that references contract… in the ServiceModel client configuration section 无法在ServiceModel客户端配置部分中找到引用合同“IAuthenticationService”的默认端点元素 - Could not find default endpoint element that references contract 'IAuthenticationService' in the ServiceModel client configuration section 在ServiceModel客户端配置部分中找不到引用contract的默认终结点元素。 - Could not find default endpoint element that references contract.in the ServiceModel client configuration section 在 ServiceModel 客户端配置部分中找不到名称为“xxxxx”且合同为“yyy”的端点元素 - Could not find endpoint element with name 'xxxxx' and contract 'yyy' in the ServiceModel client configuration section WCF错误 - 找不到引用合同的默认端点元素 - WCF Error - Could not find default endpoint element that references contract 在WCF中找不到引用合同的默认终结点元素 - Could not find default endpoint element that references contract in WCF WCF 安装程序 class - 找不到引用合同的默认端点元素 - WCF installer class - Could not find default endpoint element that references contract 找不到引用合同的默认端点元素 - 托管wcf - Could not find default endpoint element that references contract - Hosting wcf 找不到引用合同的默认端点元素 - Could not find default endpoint element that references contract
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM