2011-10-19 5 views
13

に限定しているようだ私は設定可能な数をスピンアップシンプルなUIを持つメッセージセキュリティとInstanceContextMode.PerCallWCF最大インスタンス10

を使用して結合wsHttp上で暴露さIIS7.5でホストされているシンプルなWCFサービスを持っています各スレッドはサービスを呼び出します。

perfmonカウンタServiceModel4.Instancesを追加しました。作成され、サービスを呼び出すスレッドの数にかかわらず、perfmonはサービスが最大10のインスタンスを作成することを示します。

次のように私のクライアントの設定は次のように

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <bindings> 
    <wsHttpBinding> 

     <binding name="WSHttpBinding_IService3"> 
     <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
      realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
      algorithmSuite="Default" establishSecurityContext="false" /> 
     </security> 
     </binding> 

    </wsHttpBinding> 
    </bindings> 
    <client> 

    <endpoint address="http://localhost/NGCInstancing/Service3.svc/~/Service3.svc" 
     binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService3" 
     contract="NGCSecPerCall.IService3" name="WSHttpBinding_IService3"> 
     <identity> 
     <servicePrincipalName value="host/RB-T510" /> 
     </identity> 
    </endpoint> 

    </client> 
</system.serviceModel> 
</configuration> 

私のサービスの設定は次のとおりです。

<?xml version="1.0"?> 
<system.serviceModel> 
    <configuration> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="SecPerCallBehaviour"> 
        <serviceThrottling maxConcurrentCalls="30" maxConcurrentSessions="1000" 
        maxConcurrentInstances="30" /> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
       <behavior name=""> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
    <bindings> 
     <wsHttpBinding> 
      <binding name="BindingMessageSecPerCall" > 
      <security mode="Message"> 
      <!-- it's by setting establishSecurityContext to false that we enable per call instancing with security --> 
      <message establishSecurityContext="false" /> 
      </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service name="ServiceInstancingDemo.Service3" behaviorConfiguration="SecPerCallBehaviour"> 
     <endpoint address="~/Service3.svc" 
     binding="wsHttpBinding" bindingConfiguration="BindingMessageSecPerCall" 
     contract="ServiceInstancingDemo.IService3" /> 
     </service> 
    </services> 
    </configuration> 
</system.serviceModel> 

次のようにクライアントコードは次のとおりです。

private void btnSecPerCall_Click(object sender, EventArgs e) 
    { 
     int i; 
     int requests; 
     int delay; 

     lblStatus.Text = ""; 

     DateTime startTime = DateTime.Now; 
     this.listBox1.Items.Add("start time=" + DateTime.Now); 

     delay = Convert.ToInt16(txtDelay.Text); 
     requests = Convert.ToInt16(txtRequests.Text); 

     Task<string>[] result; 
     result = new Task<string>[requests]; 

     for (i = 0; i < requests; i++) 
     { 
      result[i] = Task<string>.Factory.StartNew(() => _ngcSecPerCall.WaitThenReturnString(delay)); 
     } 

     for (i = 0; i < requests; i++) 
     { 
      this.listBox1.Items.Add(result[i].Result); 
     } 

     DateTime endTime = DateTime.Now; 
     TimeSpan ts = endTime - startTime; 
     lblStatus.Text = "Finished! Time taken= " + ts.Seconds + " seconds"; 

     this.listBox1.Items.Add("end time=" + DateTime.Now); 
    } 

私のサービスコードがあります次のようになります。

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
public class Service3 : IService3 
{ 
    private int m_counter; 

    public string WaitThenReturnString(int waitMilliSeconds) 
    { 
     System.Threading.Thread.Sleep(waitMilliSeconds); 
     int maxT, workCT; 
     System.Threading.ThreadPool.GetMaxThreads(out maxT, out workCT); 
     m_counter++; 
     return String.Format("Incrementing counter to {0}.\r\nSession Id: {1}. Threads {2}, {3}", m_counter, OperationContext.Current.SessionId, maxT, workCT); 
    } 
} 

サービスは、スレッド数が400,400を返します。

サービスが10個以上のインスタンスを作成することを拒否した理由は誰にも分かりますか?

サービスのコピーを作成しますが、<security mode="None"/>のwsHttpバインディングを作成した場合、サービスはより多くのインスタンスを作成します。

答えて

20

Windows ServerまたはWindows 7でテストしていますか?私が尋ねる理由は、クライアントOSバージョンのIISには10の接続制限があるということです。これは、クライアントOSがサーバ環境で使用されないようにするためです。

+0

これは有望ですね!私はWindows 7を使用しています。私は明日win2008 VMに展開して戻ってきます。 –

+1

はい、それでした。 Win 2008 VMでテストするとすばらしいことです。多くのおかげでGraymatter –

2

MaxConcurrentSessions documentationには、同じAppDomainからのクライアント要求の最適化が記載されています。サンプルコードは、基本的にサービス上の同じソケットに当たっています。クライアントごとに調整が行われるため、サービスの動作に影響を与える可能性があります。また、MaxConcurrentSessionsのデフォルト値は10であるため、configがWCFのデフォルト値を変更していない可能性があります。

セキュリティを有効にすると、クライアントごとに「セッション」が確立され、送信された各要求をすべての呼び出しで認証する必要がないため、合計スレッドに影響します。これらのセキュリティ「セッション」はMaxConcurrentSessions合計に加算されます。

+0

異なるバインディングで同じサービスが実装されていると付け加えてください。新しいバインドもwsHttpですが、があります。このサービスに対して同じクライアントを実行すると、サービスは10以上のインスタンスをうまく回転させます。私は、新しいバインディングのために、セキュリティコンテキストを確立する必要がないため、セッションは使用されていないと思います。私はあなたが10がデフォルトのMaxConcurrentSessionsであるという事実を持っていると思いますが、私の設定はこの値を1000に変更しようとします。実行時に使用される実際の設定を確認する方法は誰にでも分かりますか? –

+0

私はWin2008 VMにテストを移しましたが、今はうまくいきます - 私はWin7ホストに乗っていた10人ではなく61人のインスタンスを取得します。大変感謝しています。 –

1

クライアントとサーバーを同じマシンで実行していますか?それから、利用可能なスレッドのために戦っているかもしれません。

別のPCで実行している場合は、クライアントとサーバーの両方で以下の設定変更を行ってください。

http://www.codeproject.com/KB/webservices/quickwins.aspx

クライアントが同じサーバーに10件の以上のリクエストを生成していない可能性があります。ですから、上記の設定をまずクライアントとサーバの両方で試してみてください。

もちろん、Windows Serverが必要です。それ以外の場合、Windows 7のIIS制限になります。

関連する問題