【发布时间】:2020-11-12 15:47:54
【问题描述】:
我需要调用带有 PFX 证书的 SOAP Web 服务。 我正在尝试在 .NET 4.7.2 控制台应用程序中编写它。 以下是我写的。
public async Task<string> CreateSoapEnvelope()
{
string soapString = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:b2b=""Some_URL"">
<soapenv:Header/>
<soapenv:Body>
SOAP_BODY
</soapenv:Body>
</soapenv:Envelope>";
HttpResponseMessage response = await PostXmlRequest("CLIENT_URL", soapString);
string content = await response.Content.ReadAsStringAsync();
return content;
}
public static async Task<HttpResponseMessage> PostXmlRequest(string baseUrl, string xmlString)
{
try
{
// Create HttpClientHandler instance
var handler = new HttpClientHandler();
// Add the certificate
var certPath = @"PathToCertificate"; // Path to PFX fle
var cert = new X509Certificate2(certPath, "Password");
handler.ClientCertificates.Add(cert);
using (var httpClient = new HttpClient(handler))
{
var httpContent = new StringContent(xmlString, Encoding.UTF8, "text/xml");
httpContent.Headers.Add("SOAPAction", "");
return await httpClient.PostAsync(baseUrl, httpContent);
}
}catch(Exception ex)
{
}
return null;
}
现在当我调用 CreateSoapEnvelope() 时,它总是出现 InternalServerError 错误。
以下是我收到的故障字符串。
<faultstring>No signature in message! (from client). Rejected by filter; SOAP fault sent.Rejected by filter; SOAP fault sent. </faultstring><detail><service_error_message>No signature in message!</service_error_message>
我做错了吗?我对 SOAP 和 PFX 完全陌生。任何帮助表示赞赏。
【问题讨论】:
-
听起来服务器拒绝您的内容,而不是您的 TLS 客户端身份验证证书,并且它希望您的内容以某种方式签名(也许它甚至不使用 TLS 客户端身份验证,但只是期望签名消息)。
-
好的。这有帮助。如果是这样,让我与服务负责人核实一下。
标签: c# soap certificate soapui pfx