2011-10-15 99 views
13

我有我的WCF服務的以下配置:WCF應該是什麼endpointConfigurationName?

<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」,但我試過並得到以下錯誤消息:

無法找到端點元素名稱'After.ConfigName',並在ServiceModel客戶端配置部分簽訂'NGC.IService1'。這可能是因爲沒有爲您的應用程序找到配置文件,或者因爲在客戶端元素中找不到匹配此名稱的端點元素。

任何人都可以請幫忙嗎?

回答

22

您將傳遞您想要使用的相應客戶端端點的name屬性的值。例如,如果您想使用第三個端點:

new NGC.Service1Client("WSHttpBinding_IService1") 
+0

就是這樣,謝謝。 –