When I execute a SOAP request, I get the response Content is not allowed in prolog.
So far I have tried:
- adding a declaration (with different parameters)
- changing the encoding
- removing any characters in prolog (there aren't any)
- changing the namespace order
- and more I cannot probably remember
The XML is valid and well formed, so I have no idea, where my mistake is.
Here is my code:
// Set the request text.
string text = @"<ns2:Envelope xmlns:ns2=""http://www.w3.org/2003/05/soap-envelope"">
<ns2:Header>
...
</ns2:Header>
<ns2:Body>
...
</ns2:Body>
</ns2:Envelope>";
// Create the XDocument object.
var reqDocument = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), XElement.Parse(text));
// Create the web request.
var request = (HttpWebRequest)WebRequest.Create(@"https://example.com");
request.Method = "POST";
// Send the web request.
using (Stream stream = request.GetRequestStream())
reqDocument.Save(stream);
// Get the response.
string response = null;
using (WebResponse ws = request.GetResponse())
using (var rd = new StreamReader(ws.GetResponseStream()))
response = rd.ReadToEnd();
I also tried to include the header in the request. Same result.
Here is another (anonymous) example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Envelope xmlns="http://example.com" xmlns:ns2="http://www.w3.org/2003/05/soap-envelope" xmlns:ns3="http://example.com">
<ns2:Header>
<Auth>
<UserName>user</UserName>
</Auth>
</ns2:Header>
<ns2:Body>
<ns3:Customer>
<CustomerCode>22222222</CustomerCode>
</ns3:Customer>
</ns2:Body>
</ns2:Envelope>