2009-10-09 8 views
9

を送信しない:コードでWCF TransportCredentialOnlyは、私は、次のWCFクライアントの設定持っているユーザー名とパスワード

<basicHttpBinding> 
    <binding name="basicHttpOCCWS" closeTimeout="00:01:00" openTimeout="00:01:00" 
       receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" 
       bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="100000000" maxBufferPoolSize="524288" 
       maxReceivedMessageSize="100000000" messageEncoding="Text" 
       textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" 
        maxArrayLength="16384" maxBytesPerRead="4096" 
        maxNameTableCharCount="16384" /> 
     <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="Basic" />    
     </security> 
    </binding> 
</basicHttpBinding> 

を次のように、私は、ユーザー名とパスワードを設定しています:

client.ClientCredentials.UserName.UserName = _cacledUserId; 
client.ClientCredentials.UserName.Password = _cachedPassword; 

ただし、WebサービスをTomcatで実行中にエラーが返されます。

"セキュリティコンテキストで認証オブジェクトが見つかりませんでした。"

私はHTTPヘッダを見てみると、以下のように、それは資格情報が欠落しています。

POST /occ600webservice/services/OCC_WS HTTP/1.1 
Content-Type: application/soap+xml; charset=utf-8; action="" 
Host: 192.54.173.130:8080 
Content-Length: 2223 
Expect: 100-continue 

がなぜ私の資格情報が送信されませんか?

TIA。同じ問題に遭遇し、他人のために

クラウス

+0

で適切な書式を設定するには、コードセクションとXMLセクションを強調表示し、エディタツールバーの "コード"ボタン(010 101)をクリックするか、キーボードのCtrl + Kキーを押します。大きな違いをもたらす! –

答えて

21

、このようなセキュアなWebサービスのリソースへの各呼び出しをラップ:

  • Inserting headers 1
  • var client = new WCClient(); 
    
    using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) 
    { 
        var httpRequestProperty = new HttpRequestMessageProperty(); 
        httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = 
        "Basic " + 
        Convert.ToBase64String(Encoding.ASCII.GetBytes(
          client.ClientCredentials.UserName.UserName + ":" + 
          client.ClientCredentials.UserName.Password)); 
    
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = 
           httpRequestProperty; 
    
        client.DoSomething(); 
    } 
    

    には、以下のリンクを参照してください。

  • Inserting headers 2
+0

+1優秀 - そのお返事ありがとうございます! –

+0

@ e28Markaveli>私はこれを試しましたが、サービスメソッド(client.DoSomthing())を呼び出すときに、私は例外が発生します:クライアント認証スキーム 'Basic'でHTTPリクエストが不正です。サーバーから受信した認証ヘッダーは 'Basic realm = \ "localhost \でした。セキュリティーなしでこれらのクライアントの譲渡を完全に渡す必要があります。 – Banshee

+1

サービス構成の問題のように聞こえるサービスが基本認証方式に設定されていますか? –

2

セキュリティ要素はまた、ユーザ名がそれ以外の輸送はあなたが記入ClientCredentials.UserNameオブジェクトを使用することを認識していないことをclientCredentialTypeを指定するメッセージ要素を含めるように変更してみてください。

<security mode="TransportCredentialOnly"> 
    <transport clientCredentialType="Basic" proxyCredentialType="None" /> 
    <message clientCredentialType="UserName"/> 
</security> 
関連する問題