2011-10-15 28 views
13

Tôi có cấu hình sau cho dịch vụ WCF của tôi:WCF cái gì sẽ là 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> 

Tôi có thể gọi cho dịch vụ với mã khách hàng như sau:

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

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

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

Các cấu hình cho khách hàng mà các cuộc gọi dịch vụ như sau:

<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> 

Vấn đề là, tôi muốn thêm một điểm cuối khác mà sẽ thực hiện cùng một chức năng nhưng với một hành vi khác. Để làm điều này, tôi nghĩ rằng tôi sẽ cần phải vượt qua một chuỗi của enpointConfigurationName đến hàm tạo trong dòng = new NGC.Service1Client. Tôi không biết chuỗi nào tôi cần phải vượt qua - tôi đã mong đợi nó là tên cấu hình điểm cuối "After.ConfigName" nhưng tôi đã thử cách này và nhận được thông báo lỗi sau:

Không thể tìm thấy phần tử điểm cuối bằng tên 'After.ConfigName' và hợp đồng 'NGC.IService1' trong phần cấu hình máy khách ServiceModel. Điều này có thể là do không tìm thấy tệp cấu hình nào cho ứng dụng của bạn, hoặc vì không có phần tử điểm cuối nào khớp với tên này có thể được tìm thấy trong phần tử máy khách.

Mọi người có thể giúp bạn không?

Trả lời

22

Bạn sẽ chuyển giá trị của thuộc tính name của điểm cuối ứng dụng khách tương ứng mà bạn muốn sử dụng. Ví dụ: nếu bạn muốn sử dụng điểm cuối thứ ba:

new NGC.Service1Client("WSHttpBinding_IService1") 
+0

Đó là, cảm ơn. –

Các vấn đề liên quan