我需要调用一个SOAPendpoint,我正在使用NET Core。 内置的WCF功能似乎无法处理我需要它做的事情,因为我需要在主体本身中设置一个SecurityToken,而它没有这个功能。 我已经到处浏览,寻找潜在的解决方案,但还没有一个对我有效。 这是我当前的代码:
public async Task<string> CreateSoapEnvelope()
{
string soapString = $@"
<soap:Envelope
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:wsa=""http://schemas.xmlsoap.org/ws/2004/08/addressing"">
<soap:Header>
<wsa:Action>actionAddress</wsa:Action>
<wsa:MessageID>uuid</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:To>address</wsa:To>
</soap:Header>
<soap:Body>
<Transaction>
<Input>
<Inquiry> !--Request Data Here --!
</Inquiry>
</Input>
<SecurityToken SepecialUserId=####### Token=STS TOKEN HERE/>
</Transaction>
</soap:Body>
</soap:Envelope>";
HttpResponseMessage response = await PostXmlRequest(Configuration.GetValue<string>("AppKeys:EndpointAddress"), soapString);
string content = await response.Content.ReadAsStringAsync();
return content;
}
public static async Task<HttpResponseMessage> PostXmlRequest(string baseUrl, string xmlString)
{
using (var httpClient = new HttpClient())
{
var httpContent = new StringContent(xmlString, Encoding.UTF8, "text/xml");
httpContent.Headers.Add("Transaction", "actionaddress");
return await httpClient.PostAsync(baseUrl, httpContent);
}
}
每次运行此程序时,我都会从endpoint返回以下结果:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<soapenv:Fault><faultcode>soapenv:VersionMismatch</faultcode><faultstring>Only SOAP 1.1 or SOAP 1.2 messages are supported in the system</faultstring><detail></detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
有人对如何解决这个有什么建议吗? 老实说,我在SOAP方面的经验有限,我已经花了两天多的时间来研究这个问题。 在Postman中执行这个相同的XML正文成功地发布了消息,没有出现问题。
您正在将Content-Type
头设置为什么?
本页建议应
内容类型:Application/SOAP+XML