2017-10-26 19 views
1

私が取り組んでいる古いWCFサービス/クライアントが得られました。新しい(静的な)ロギングシステムを追加しました。実際には現在、いくつかの負荷テストを行っています。WCF/wsHttpBinding/Message Security - BadTokenRequest

「リモートエンドポイントとのセキュリティネゴシエーションが失敗したため、セキュリティで保護されたチャネルを開くことができません」という疑わしい散発的な問題が発生しています。 BadContextTokenのSenderとサブコードのフォールト名でCommunicationExceptionを取得したことに気付きました。

奇妙なことですが、私は2〜4の正しい応答を得て、次にこれらの例外が慌てて、再び良い応答を得るようになります。

これは、WCFへの私の最初の本当の進出で、これまでのところ、それを愛していない:)

サービスのweb.config:

<system.serviceModel> 
    <bindings> 
    <wsHttpBinding> 
     <security mode="Message"> 
     <message clientCredentialType="UserName" /> 
     </security> 
    </wsHttpBinding> 
    </bindings> 
    <services> 
    <service behaviorConfiguration="ServiceBehavior" name="MyNamespace.MyService"> 
     <endpoint address="" binding="wsHttpBinding" contract="MyNamespace.IMyService" bindingConfiguration="wsMessage"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
    </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="ServiceBehavior"> 
     <serviceMetadata httpGetEnabled="false" /> 
     <serviceCredentials> 
      <serviceCertificate findValue="MyValue" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" /> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyNamespace.UserNamePassValidator, MyNamespace" /> 
     </serviceCredentials> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

とクライアント側で、クライアントがそのようなとしてインスタンス化されています。

var binding = new WSHttpBinding(); 
binding.Name = "WSHttpBinding_IMyService"; 
binding.Security.Mode = SecurityMode.Message; 
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; 

var client = new MyService(binding, "http://myserver:8080/myapp/service.svc"); 

var endpointIdentity = new DnsEndpointIdentity("MyValue"); // Match the certificate name used by the server 

client.Endpoint.Address = new EndpointAddress(new Uri("http://myserver:8080/myapp/service.svc"), endpointIdentity, client.Endpoint.Address.Headers); 

var creds = client.ClientCredentials; 

creds.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
creds.UserName.UserName = "myuser"; 
creds.UserName.Password = "mypassword"; 

string retVal = client.SendRequest(); // SendRequest == one of the methods on my IMyService, returns a string. This is also where I sporadically see my error when load testing. 

私はこのWCF設定で私を助けてくれることを嬉しく思います!

答えて

0

これらはあなたのweb.configファイルに役立つの追加次のようになります。

    あなた以来
  1. タイムアウト(おそらくないあなたの場合、」:通常「ランダム」行動のこの種のに依存する場合があります

    <behaviors> 
        <serviceBehaviors> 
         <behavior name="CalculatorServiceBehavior"> 
          <serviceDebug includeExceptionDetailInFaults="False" /> 
          <serviceMetadata httpGetEnabled="True"/> 
          <serviceThrottling maxConcurrentCalls="20" maxConcurrentInstances="100"/> 
         </behavior> 
        </serviceBehaviors> 
    </behaviors> 
    
    <binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="1048576" maxBufferSize="1048576" maxBufferPoolSize="1048576"> 
        <readerQuotas maxDepth="32" maxArrayLength="1048576" maxStringContentLength="1048576"/> 
    </binding> 
    

    d)別の例外があります。

  2. 接続が多すぎます:クライアントがあまりにも多くの接続を開くと、接続を開くことを忘れてしまい、デフォルトの許容最大値を超えてしまいます(コンテキストによっては10接続かもしれません)。 web.configを変更した場合にこれを実行できます。maxConcurrentCallsmaxConcurrentInstances
  3. これらのエラーはランダムではなく、特定のメッセージに固有のものである可能性があります。もしそうなら、それは(すなわち、それは大きすぎるのです)、その大きさに次のようになります。もう一度、あなたはWCF tracingをオンにした場合、あなたがより多くの情報を取得しますmaxReceivedMessageSizemaxBufferSizemaxBufferPoolSizeともちろんreaderQuotas

を設定あなたのweb.configファイルを変更します。

+0

何らかの理由でこれが役に立たない場合は、さらに詳しい情報が必要なのかどうか迷ってください。 –