2013-01-14 1 views
6

WSDLからVisual Studio 2012によって実装されたWCF SOAPコンシューマがあります。 WSDLはPeopleToolsによって生成されました。ベースオブジェクトのタイプはSystem.ServiceModel.ClientBaseです。C#では、WSSEプレーンテキスト認証を使用するWCF SOAPコンシューマですか?

  • ない平文WSSE資格:次の2つの問題に気付くでしょう

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 
        <s:Header> 
         <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action> 
         <a:MessageID>urn:uuid:3cc3f2ca-c647-466c-b38b-f2423462c837</a:MessageID> 
         <a:ReplyTo> 
          <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> 
         </a:ReplyTo> 
         <a:To s:mustUnderstand="1">http://[internal URL to soap listener]</a:To> 
        </s:Header> 
        <s:Body> 
         <t:RequestSecurityToken Context="uuid-7db82975-2b22-4236-94a1-b3344a0bf04d-1" xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust"> 
          <t:TokenType>http://schemas.xmlsoap.org/ws/2005/02/sc/sct</t:TokenType> 
          <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType> 
          <t:KeySize>256</t:KeySize> 
          <t:BinaryExchange ValueType=" http://schemas.xmlsoap.org/ws/2005/02/trust/tlsnego" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">FgMBAFoBAABWAwFQ9IhUFGUO6tCH+0baQ0n/3us//MMXzQA78Udm4xFj5gAAGAAvADUABQAKwBPAFMAJwAoAMgA4ABMABAEAABX/AQABAAAKAAYABAAXABgACwACAQA=</t:BinaryExchange> 
         </t:RequestSecurityToken> 
        </s:Body> 
    </s:Envelope> 
    

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://xmlns.oracle.com/Enterprise/Tools/schemas"> 
        <soapenv:Header> 
         <wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
          <wsse:UsernameToken> 
           <wsse:Username>[plain text username goes here]</wsse:Username> 
           <wsse:Password>[plain text password goes here]</wsse:Password> 
          </wsse:UsernameToken> 
         </wsse:Security> 
        </soapenv:Header> 
        <soapenv:Body> 
         <sch:InputParameters> 
          <Last_Name>Aren</Last_Name> 
          <First_Name>Cambre</First_Name> 
         </sch:InputParameters> 
        </soapenv:Body> 
    </soapenv:Envelope> 
    

    ここでは得ることができます最も近いです。

    私は似ているようにSOAPリクエストを必要とします。サービスが使用しない資格情報のバイナリ形式を渡します。

  • 認証はBodyで、Headerではありません。
  • 要求にはInputParametersが省略されています。

ここで不可欠なC#のコードです:

var service = new ServiceWithBizarreNameFromPeoplesoft(); 

if (service.ClientCredentials == null) 
    throw new NullReferenceException(); 
service.ClientCredentials.UserName.UserName = "test"; 
service.ClientCredentials.UserName.Password = "password"; 

var binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential) {Security = new WSHttpSecurity()}; 
service.Endpoint.Binding = binding; 

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; 
binding.Security.Mode = SecurityMode.Message; 

var input = new InputParameters { Last_Name = "Cambre", First_Name = "Aren" }; 

var returnData = service.BizarrePeopleSoftNameForMethod(input); 

そこにはHTTP層のセキュリティはいない、とトランスポートがSSLで暗号化されます。認証はSOAPメッセージにのみ基づいています。

+0

WSDLが悪いようですね。それがWSEの時代に作られたのであれば、それは非標準である可能性が高いです。 –

+0

興味深い。 WSDLが悪いと思うのはなぜですか? –

+0

それは悪いクライアントを構築するという事実、そしてそれがWSEの時代からあると思われるという事実。たとえば、SOAP 1.1を使用しています。 –

答えて

9

これはWS-SecureConversationトークンの要求です。 EstablishSecurityContextプロパティをfalseに変更しない限り、既定ではWSHttpSecurityによって使用されます。

var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);  
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; 

これはSOAP 1.1とUserNameトークンを使用し、HTTPS転送を必要とします。

編集:テスト用

HTTPSせずに結合、このカスタムを使用しよう:

var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement(); 
securityElement.AllowInsecureTransport = true; 

var encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8); 
var transportElement = new HttpTransportBindingElement(); 

var binding = new CustomBinding(securityElement, encodingElement, transportElement); 
+0

ありがとうございます。 'ClientCredentialType'は' BasicHttpMessageCredentialType'でなければならず、 'MessageCredentialType'ではないようです。今私はWiresharkを使ってネットワーク接続を盗聴できるようにHTTPを使用しています。 HTTPSを必要とするような動作を無効にする方法はありますか?私は 'binding.Security.Mode'の変更について調査しましたが、これが許可するオプションはないと思われます。 –

+0

ありがとう、私は最初の例を修正し、HTTPSなしでテストするためのもう1つのオプションを追加しました。 –

+0

おっと、これは本当に近いです! Wiresharkは通信が成功したことを示していますが、.NET Frameworkはこの応答が気に入らないことを示しています: "**セキュリティプロセッサはメッセージにセキュリティヘッダーを見つけることができませんでした。これは、メッセージがセキュリティ保護されていないフォルトか、これは、サービスがセキュリティのために構成されており、クライアントがセキュリティを使用していない場合に発生する可能性があります。** "オプションの調査中... –

-1

これは、基本的なユーザー名パスワード認証を使用するトランスポートセキュリティを使用するwsHttpBindingsのように見えます。

これらの行は私に間違っ見る:

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; 
binding.Security.Mode = SecurityMode.Message; 

は、ここで私はその後、コードは次のようになりますあなたのアプリやweb.configファイル

<bindings> 
    <wsHttpBinding> 
    <binding name="ws" > 
     <security mode="Transport"> 
     <transport clientCredentialType="Basic" proxyCredentialType="Basic" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

<client> 
    <endpoint address="http://www.bla.com/webservice" binding="basicHttpBinding" contract="bla.IService" name="ws" /> 
</client> 

にこれが設定され見ることが期待される方法は次のとおりです。

var service = new GeneratedProxyClient("basic"); 
service.ClientCredentials.UserName.UserName = "test"; 
service.ClientCredentials.UserName.Password = "password"; 
var input = new InputParameters { Last_Name = "Cambre", First_Name = "Aren" }; 
var returnData = service.BizarrePeopleSoftNameForMethod(input); 

ここで詳しく説明してください - >http://msdn.microsoft.com/en-us/library/ms733775.aspx

+0

ありがとうございますが、基本認証を使用していません。 HTTPレイヤーには認証がありません。また、 '' var service = new ServiceWithBizarreNameFromPeoplesoft() 'の引数として' 'basic ''を使うとエラーになります。どうやら、単一の文字列を渡すと、その文字列はエンドポイント要素の名前であると考えられます。これはhttp://msdn.microsoft.com/en-us/library/ms574925.aspxでサポートされているようです。 –

関連する問題