2016-09-30 11 views
0

基本認証でWCF basicHttpBindingを使用すると、IISリセット後の最初の要求が、ユーザーなしで送信されます(許可なし:基本...)。データ)基本認証付きbasicHttpBindingユーザーなし/データ渡しの最初の要求を送信

コード:

client.ClientCredentials.UserName.UserName = "myUserName"; 
client.ClientCredentials.UserName.Password = "myPassword"; 
string anything = client.getValue(@"anyParam.."); 

設定:フィドラーによってモニターした後

<basicHttpBinding> 
    <binding name="ServiceNameHereServiceBinding" > 
     <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Basic" proxyCredentialType="None" 
        realm=""> 
      </transport> 
     </security> 
    </binding> 
</basicHttpBinding> 

を、私は最初の要求は必ず行く(401を返す、ことがわかりました認証ヘッダーがまったくない場合)、別の要求が出て505エラーを返します。 その後、このサービスはそれ以降のすべての要求に適しています。

答えて

0

私は解決策を見つけましたが、私はあなたと共有してもいいと思っています。

ソリューションはここhttp://plainoldstan.blogspot.ca/2008/07/avoid-http-401-roundtrip-with-adding.htmlスタニスラフDvoychenko

ことであるそれだけでこれを行うには、クライアントに依存する代わりに、基本認証ヘッダーを自分で作成することであります。ボックスクライアントからエンドポイントが事前認証されていると見なすためです。

// Assign client.ClientCredentials.UserName.UserName and client.ClientCredentials.UserName.Password 
SetupClientAuthentication(); 

HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty(); 

httpRequestProperty.Headers[HttpRequestHeader.Authorization] = "Basic " + 
    Convert.ToBase64String(Encoding.ASCII.GetBytes(client.ClientCredentials.UserName.UserName + ":" + 
    client.ClientCredentials.UserName.Password)); 

using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) 
{ 
    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = 
     httpRequestProperty; 

    // Invoke client 
} 
関連する問題