2016-03-18 13 views
5

サービスリファレンスを使用してC#でSSL SOAPサービスホストに接続しようとしています。 これは私の要求メッセージである:「サービスリファレンス」経由でSSL SOAPホストに接続し、セキュリティヘッダーを渡します

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <s:Header> 
     <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo/zwMmtdsVhFsAVDkQbiV/4AAAAA1zXtnc72UEm+4tlKzvCxsvN6OC2prvRIljIX4XzHKEYACQAA</VsDebuggerCausalityData> 
     <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <u:Timestamp u:Id="_0"> 
       <u:Created>2016-03-18T12:45:27.558Z</u:Created> 
       <u:Expires>2016-03-18T12:50:27.558Z</u:Expires> 
      </u:Timestamp> 
      <o:UsernameToken u:Id="uuid-2c7986ba-eee5-4411-90a9-a02b625c55ff-1"> 
       <o:Username>MyUserName</o:Username> 
       <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MyPlainPassword</o:Password> 
      </o:UsernameToken> 
     </o:Security> 
    </s:Header> 
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <generateId xmlns="http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/IndividualCommercialService"/> 
    </s:Body> 
</s:Envelope> 

は、これは私のサービスは、ホストに送信するメッセージです。しかし、ホストは以下のように返されます。

セキュリティプロセッサはメッセージ内にセキュリティヘッダーを見つけることができませんでした。これは、メッセージが保護されていない障害であるか、または通信相手間にバインディングの不一致があるためです。これは、サービスがセキュリティのために構成されており、クライアントがセキュリティを使用していない場合に発生します。

は、これは私の設定ファイルである:

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

    <system.serviceModel> 

    <bindings> 
     <customBinding> 
     <binding name="myBinding"> 
      <textMessageEncoding messageVersion="Soap11" /> 
      <security authenticationMode="UserNameOverTransport" 
        messageSecurityVersion="WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10" > 
      </security> 

      <httpsTransport /> 
     </binding> 
     </customBinding> 
    </bindings> 
    <client> 
     <endpoint address="https://{URL}" 
     binding="customBinding" 
       bindingConfiguration="myBinding" 
     contract="ServiceReference2.MyService" 
       name="IndividualCommercialService" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

私はSOAPUIまたは他のHTTP POSTメソッドを経由して、同じXMLを送信するときに、それが正常に動作しますが。

私はまた、以下のように渡す/証明書とユーザーを抽出し、添付:

private static X509Certificate2 DownloadSslCertificate(string strDNSEntry) 
     { 

      X509Certificate2 cert = null; 
      using (TcpClient client = new TcpClient()) 
      { 
       //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;   
       client.Connect(strDNSEntry, 443); 

       SslStream ssl = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null); 
       try 
       { 
        ssl.AuthenticateAsClient(strDNSEntry); 
       } 
       catch (AuthenticationException e) 
       { 
        //log.Debug(e.Message); 
        ssl.Close(); 
        client.Close(); 
        return cert; 
       } 
       catch (Exception e) 
       { 
        //log.Debug(e.Message); 
        ssl.Close(); 
        client.Close(); 
        return cert; 
       } 
       cert = new X509Certificate2(ssl.RemoteCertificate); 
       ssl.Close(); 
       client.Close(); 
       return cert; 
      } 
     } 

     private static void Main(string[] args){ 
       var proxy = new MyService(); 

       var uri = proxy.Endpoint.Address.Uri; 
       var cer = DownloadSslCertificate(uri.DnsSafeHost); 

       EndpointIdentity identity = EndpointIdentity.CreateDnsIdentity(cer.Subject.Replace("CN=", "")); 
       EndpointAddress address = new EndpointAddress(proxy.Endpoint.Address.Uri, identity); 

       proxy.Endpoint.Address = address; 

       proxy.ClientCredentials.UserName.UserName = "MyUserName"; 
       proxy.ClientCredentials.UserName.Password = "MyPlainPassword"; 
       proxy.ClientCredentials.ServiceCertificate.DefaultCertificate = cer; 

       proxy.HellowWorld(); 
      } 

私は、証明書を取得しています方法が正しいかどうか、また、HTTPポストが機能する理由かどうかわかりませんが、私のサービス参照呼び出しは行いません。

ご協力いただきありがとうございます。

乾杯

答えて

1

は隠しファイルが最初のソリューションエクスプローラで[すべてのファイルを選択し見るためにWSDL(サービス参照)の中を見てみてください。 You`ll SEサービス参照Reference.svcmap内部 - > Reference.csは、このファイルの内部をのProtectionLevel = System.Net.Security.ProtectionLevel.Sign

[System.ServiceModel.ServiceContractAttribute(Namespace = "http://www.your.url/Service/", ConfigurationName = "Service.Service", ProtectionLevel = System.Net.Security.ProtectionLevel.Sign)] 

以下のように助けるべきである追加します君は。通常、自動生成されたプロキシを変更することは本当に悪い考えですが、それが唯一のオプションだと思われます。

+0

ありがとう、ウラジミール、私はこれをテストし、あなたに戻ってきます。 – Barsham

+0

ようこそ、結果を知らせてください – Vladimir

関連する問題