私は尋ねる前にすべてを試しました。私はURL https://somethingで非常に簡単なサービスを持っています。 https://something?wsdlを使用してWSDLを取得できます。ここでは、Web参照と同様にサービス参照でこれを追加しました。しかし私がそれを呼び出すと、SOAPヘッダーは送信されません(Fiddlerでチェックされます)。 SOAP UIでエラーなしで呼び出すことができます。 (BTWサーバーはWS-Securityを使用しています)。ここでは、SOAP UIリクエストを垣間見ることができます。シンプルソープサービスを呼び出せませんか?
<soapenv:Envelope xmlns:ns=""http://www.customs.pcfc.com/Schema/Declaration/TraderInboundServiceParameters/1.0"" xmlns:ns1=""http://www.customs.pcfc.com/Schema/Common/2.0"" xmlns:sad=""http://www.customs.pcfc.com/Schema/Declaration/SAD"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand=""1"" xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd""><wsse:BinarySecurityToken EncodingType=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"" ValueType=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"" wsu:Id=""CertId-1270251257"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">xxx</wsse:BinarySecurityToken><ds:Signature Id=""Signature-847101547"" xmlns:ds=""http://www.w3.org/2000/09/xmldsig#"">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm=""http://www.w3.org/2001/10/xml-exc-c14n#""/>
<ds:SignatureMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#rsa-sha1""/>
<ds:Reference URI=""#id-2038872614"">
<ds:Transforms>
<ds:Transform Algorithm=""http://www.w3.org/2001/10/xml-exc-c14n#""/>
</ds:Transforms>
<ds:DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1""/>
<ds:DigestValue>xx</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
xxx
</ds:SignatureValue>
<ds:KeyInfo Id=""KeyId-1608734597"">
<wsse:SecurityTokenReference wsu:Id=""STRId-161586721"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd""><wsse:Reference URI=""#CertId-1270251257"" ValueType=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3""/></wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature></wsse:Security></soapenv:Header>
<soapenv:Body wsu:Id=""id-2038872614"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">
Body
</soapenv:Body>
</soapenv:Envelope>
本文はXMLでもあります。今、私はこれを試しました
var client = new WebServiceClient();
var reader = new XmlSerializer(typeof(Request));
var file = new StreamReader("a.xml");
var fileData = (DeclarationRequest)reader.Deserialize(file);
var cert = new X509Certificate2("Mycert.cer", "Pass");
client.ClientCertificates.Add(cert);
fileData.UNB.DateTime = DateTime.UtcNow;
var b = client.process(fileData);
私はInvalid Certificate
を得ています。
は、その後、私はここで私は、(再び無効な証明書)を
コンテンツタイプapplication /石鹸+ xmlのを取得していますサービス参照、
var client = new MyClient(); client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.TrustedPublisher, X509FindType.FindByIssuerName, "Iss Name"); var reader = new XmlSerializer(typeof(Request)); var file = new StreamReader("a.xml"); var fileData = (Request)reader.Deserialize(file); var request = fileData; request.UNB.DateTime = DateTime.UtcNow; ((BasicHttpBinding)client.Endpoint.Binding).Security.Mode = BasicHttpSecurityMode.Transport; ((BasicHttpBinding)client.Endpoint.Binding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; var response = client.process(request);
を試してみました。 charset = UTF-8;応答メッセージのaction = "process"がバインディングのコンテンツタイプ(text/xml; charset = utf-8)と一致しません。カスタムエンコーダを使用する場合は、IsContentTypeSupportedメソッドが正しく実装されていることを確認してください。応答の最初の695のバイトがあった。
'<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header>
</env:Header>
<env:Body>
<env:Fault><env:Code>
<env:Value>env:Receiver
</env:Value>
<env:Subcode>
<env:Value xmlns:fault="http://tempuri.org/soapfaults">fault:MessageBlocked
</env:Value>
</env:Subcode>
</env:Code><env:Reason>
<env:Text xml:lang="en">Invalid Certificate
</env:Text>
</env:Reason><env:Detail xmlns:fault="http://tempuri.org/soapfaults" fault:type="faultDetails">
</env:Detail>
</env:Fault>
</env:Body>
</env:Envelope>'.
だけに、サーバ証明書の検証を無視しますこのツールでサービスのテストを容易にする。ただし、アプリケーションインターフェイスからセキュア(SSL)エンドポイントを呼び出す場合は、サーバーから提示されたときに証明書を検証する必要があります。また、それは双方向SSL(相互認証)ですか? –