I need to call a SOAP endpoint and I am using NET Core. The built in WCF Functionality doesn't seem to handle what I need it to do, as I need to set a SecurityToken in the body itself and it doesn't have the functionality. I've browsed around in SO looking for potential solutions but none yet work for me. This is my current code:
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);
}
}
Every time I run this I get the following result back from the 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>
Does anyone have any suggestions on how to solve this? My experience with SOAP is limited to be honest, and I've spent well over two days on this issue. Executing this same XML body in Postman successfully posts without issues.