【问题标题】:WCF what should be the endpointConfigurationName?WCF的endpointConfigurationName应该是什么?
【发布时间】:2016-07-21 21:22:11
【问题描述】:

我的 WCF 服务有以下配置:

<system.serviceModel>
<services>
  <service behaviorConfiguration="After.BehaviourConfig" name="ServiceInstancingDemo.Service1">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="After.BindingConfig"
      name="After.ConfigName" contract="ServiceInstancingDemo.IService1">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://rb-t510/NGCInstancing/Service1.svc" />
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="After.BindingConfig" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferPoolSize="524288111" maxReceivedMessageSize="524288111" allowCookies="false">
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="After.BehaviourConfig">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="30" maxConcurrentInstances="2147483647" maxConcurrentSessions="30" />
    </behavior>
  </serviceBehaviors>
</behaviors>

我可以使用以下客户端代码调用服务:

NGC.Service1Client ngc = new NGC.Service1Client();

        var taskA = Task<string>.Factory.StartNew(() => ngc.WaitThenReturnString(5));

        this.listBox1.Items.Add(taskA.Result);

调用服务的客户端配置如下:

 <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="Before" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferPoolSize="524288111"
                maxReceivedMessageSize="524288111" allowCookies="false" />
            <binding name="After" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferPoolSize="524288111"
                maxReceivedMessageSize="524288111" allowCookies="false">
                <security mode="None" />
            </binding>
            <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://rb-t510/NGCInstancing/Service1.svc"
            binding="wsHttpBinding" bindingConfiguration="Before" contract="NGCInstance.IService1"
            name="Before" />
        <endpoint address="http://rb-t510/NGCInstancing/Service1.svc"
            binding="wsHttpBinding" bindingConfiguration="After" contract="NGCInstance.IService1"
            name="After" />
        <endpoint address="http://rb-t510/NGCInstancing/Service1.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
            contract="NGC.IService1" name="WSHttpBinding_IService1">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

问题是,我想添加另一个执行相同功能但行为不同的端点。为此,我想我需要将 enpointConfigurationName 的字符串传递给 line=new NGC.Service1Client 中的构造函数。我不知道我需要传递什么字符串 - 我原以为它是端点配置名称“After.ConfigName”,但我尝试了这个并收到以下错误消息:

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

有人可以帮忙吗?

【问题讨论】:

    标签: wcf


    【解决方案1】:

    您将传递您想使用的相应客户端端点的name 属性的值。例如,如果您想使用第三个端点:

    new NGC.Service1Client("WSHttpBinding_IService1")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      相关资源
      最近更新 更多