function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tsorg bankstsorg banks 

Content is not allowed in prolog. SOAP error

I'm currently trying to send a soap message to logon to my salesforce application. I send the following message:

<?xml version="1.0" encoding="utf-16"?>
<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">
  <soap:Body>
    <login xmlns="urn:enterprise.soap.sforce.com">
      <username />
      <password />
    </login>
  </soap:Body>
</soap:Envelope>

I get the following reply:

<?xml version="1.0" encoding="utf-16"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>soapenv:Client</faultcode>
      <faultstring>Content is not allowed in prolog.</faultstring>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>

I'm using a webservice test tool called webstudio (downloaded from gotdotnet). It allows me to invoke the 'login' webservice via a .net proxy called which works fines, but when I use it to invoke the 'login' method via http soap request it fails as above.

Please can anyone explain why salesforce is returning this error. Can anyone send me a complete soap request that will allow me to call the 'login' method, as I'm guessing salesforce doesn't like something in the soap I'm sending it.

Thanks very much in advance for any help.

SuperfellSuperfell
That normally mean you have some whitespace before the start of the actual XML. Can you post a capture of your complete HTTP request, rather than just the XML.
RayGRayG

I was getting the same error on a possibly related problem.  I was calling out to a third party REST API from Salesforce.  My XML data worked fine when POSTing to the EndPoint from a REST client tool (Postman plugin for Chrome), but I was forever getting "Content is not allowed in prolog" when calling out from Salesforce.  After endlessly faffing with character encoding settings I found that the thing that made the difference was setting the content-length header which I'd missed.  (I found I'd done this by comparing the request formed in the REST client using Fiddler with what I was doing in the Apex class calling out).

 

Here's what worked for me (I know you're calling in to Salesforce but it may work):

 

 

String postXML = '{set XML body here in plain text, I only used \n for newlines}';
HttpRequest req = new HttpRequest();
req.setEndpoint('{endpoint URL here}');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/xml');
req.setHeader('Content-length',string.valueof(postXML.length()));  /* <---- this line made the difference */
req.setBody(postXML);

Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());

 

 

Exception handling etc.  omitted.

 

Hope that helps someone.

Ray

Ofer GalOfer Gal

What language is this?

C# does not like "

string.valueof(postXML.length())

"

Tried Content.Headers.Add("Content-length", loginText.Length.ToString()); but then the error is:

"Bytes to be written to the stream exceed the Content-Length bytes size specified"