+ Start a Discussion

URGENT - Can i directly send/receive SOAP Messages with out using the Salesforce API ?

I am sending a soap message by posting it to the SOAP Server via a HTML Form using the below code. But i get a SOAP fault in response shown below. Can some one please put some light on what the SOAP Server needs ?? I am using the login to the Salesforce Developer edition account.
<title>XML Client for soap Servlet Example</title>
<h4>Web based SOAP Client</h4>
You can use the form below to <tt>POST</tt> XML requests to the servlet URL - https://www.salesforce.com/services/Soap/c/6.0
<form method='POST' action='https://www.salesforce.com/services/Soap/c/6.0'><textarea
 name='xml' rows='10' cols='60'>
<?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://
         <login xmlns="urn:enterprise.soap.sforce.com">
</textarea> <br>
<input type='submit' value='Send'> | <input type='reset' value='Clear'>
  <?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Body>
- <soapenv:Fault>
  <faultcode xmlns:ns1="urn:fault.enterprise.soap.sforce.com">ns1:UNKNOWN_EXCEPTION</faultcode>
  <faultstring>UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService</faultstring>
- <detail>
- <sf:fault xsi:type="sf:UnexpectedErrorFault" xmlns:sf="urn:fault.enterprise.soap.sforce.com">
  <sf:exceptionMessage>Destination URL not reset. The URL returned from login must be set in the SforceService</sf:exceptionMessage>
The SOAP endpoint requires a real soap message (i.e. one that conforms to both the SOAP 1.1 specification, and the XML schema contained within the WSDLs).

You can't generate a SOAP request from an HTML FORM Post, what you're generating is a form encoded request where part of that encoded request is a chunk of XML, this is not SOAP, a soap request contains the XML directly, has a HTTP content-type of text/xml; charset='someCharSetProbablyutf-8' and a HTTP header called SOAPAction.

Use a proxy or sniffing tool and compare the POST generated by your FORM to a POST from a soap client (or from the sample messages linked from the docs), you'll be able to see the difference.
I have tried two different ways to send the Login message.
A) Build SOAP message using soap tool kit and send it using a inhouse customized http client. The request message using this method looks as below and the corresponding output is a SOAP fault and hence we see a HTTP error.

REQUEST :SOAPMessage: msg = [SOAPEnvelopeHDOMImpl:

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

<SOAP-ENV:Header />


<login xmlns="urn:enterprise.soap.sforce.com">

<username xmlns="">dimpjain@yahoo.com</username>

<password xmlns="">*****</password>




]; attributes = [{HEADER_MAP={Cookie=SMSESSION=EmHyJYcUOApHLMAXhiPiVLjfbTqtdWcI4WNf9t9QeZxSQiqcYKDgGWF1g5NFVPTzTeXoRz2+PYNjumh/MABqV6b5gnjKhnjMBtH206sXWP87BS1BV8Iw1biKKqPSCETEie3O0kWvnpyuU1Xn9W2PKTddcy7mBGU1JsGcspOwE3I+ECYPK2GFoTQ00lyNFdCpAk1msynxoRJskts+M9dALW98GZGyjfeO6MlzAwKW5iQfCOgz8uptSEvLQ56CJfC5C2FLwP+cURZFQJBFllNEAM3It0lnEyrrrBwCzgK+FxkOTjvVcUuo/kkESph20Zj5FTbJs0kjKGT6toRngCBN/TUM4JrGpL5VGkkxCzvtU8oXvctneRTc2PhLKaLKmE4s, SOAPAction=}}]

msjava.soaptk.common.SOAPException: Unexpected response: HTTP_SERVER_ERROR with no content in the body! Status code: 500; transport name =https://www.salesforce.com/services/Soap/c/6.0, protocol HTTP

at msjava.soaptk.transport.http.SOAPHttpClient.sendRequest(SOAPHttpClient.java:185)

at Login.<init>(Login.java:171)

at Login.main(Login.java:199)

B) using a HttpsURLConnection to send the messgae. Below is the output of it.

java.io.IOException: Server returned HTTP response code: 500 for URL: https://www.salesforce.com/services/Soap/c/6.0

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1149)

at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)

at URLSample.main(URLSample.java:63)

error: <?xml version="1.0" encoding="UTF-8"?>

error: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

error: <soapenv:Body>

error: <soapenv:Fault>

error: <faultcode xmlns:ns1="urn:fault.enterprise.soap.sforce.com">ns1:UNKNOWN_EXCEPTION</faultcode>

error: <faultstring>UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService</faultstring>

error: <detail>

error: <sf:fault xsi:type="sf:UnexpectedErrorFault" xmlns:sf="urn:fault.enterprise.soap.sforce.com">

error: <sf:exceptionCode>UNKNOWN_EXCEPTION</sf:exceptionCode>

error: <sf:exceptionMessage>Destination URL not reset. The URL returned from login must be set in the SforceService</sf:exceptionMessage>

error: </sf:fault>

error: </detail>

error: </soapenv:Fault>

public class Login {
 SOAPHttpClient client;
 SOAPMessage loginResponse;
 Login(String uname, String pwd) {
 SOAPEnvelope envelope = new SOAPEnvelopeHDOMImpl();
 SOAPHeader header = envelope.createHeader(); 

    Element username = new Element("username");
    Element password = new Element("password");
//  build body 
 SOAPBodyHDOMImpl body = (SOAPBodyHDOMImpl) envelope.createBody(); 
 SOAPActionHDOMImpl action = new SOAPActionHDOMImpl("login"); 
 try {
 }catch(SOAPException e) {
    SOAPMessage request = new SOAPMessage(envelope);

/....customized code to generate token .../

    Map m = new HashMap();
    m.put("Cookie", "SMSESSION="+ token);
    request.getAttributes().put(TIAFHttpAttributes.HEADER_MAP, m);

    System.out.println("REQUEST :" + request);
     try  {
     client = new SOAPHttpClient("https://www.salesforce.com/services/Soap/c/6.0");
     } catch(IOException e){
    try {
     loginResponse = client.sendRequest(request);
    } catch(SOAPException e) {
 public static void main(String args[]) {
  Login login = new Login("dimpjain@yahoo.com", "*****");
METHOD Bimport java.net.*;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;
public class URLSample { /**
  * @param args
 public static void main(String[] args) {
   HttpsURLConnection connection = null;
  try {
        URL u = new URL("https://www.salesforce.com/services/Soap/c/6.0");
        URLConnection uc = u.openConnection();
        connection = (HttpsURLConnection) uc;
     connection.setRequestProperty("SOAPAction", "\"\"");
   connection.setRequestProperty("Expect", "100-continue");
   connection.setRequestProperty("Content-Type","text/xml; charset=utf-8");
   connection.setRequestProperty("Host", "www.salesforce.com");
        Writer wout = new OutputStreamWriter(connection.getOutputStream());
        wout.write("<?xml version=\"1.0\" encoding=\"utf-8\"?\r\n");
        wout.write("<soap:Envelope ");
        wout.write("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\r\n");
        wout.write("<login xmlns=\"urn:partner.soap.sforce.com\"\r\n");
        InputStream is = connection.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        while ( (line = br.readLine()) != null) {
         System.out.println("result: " + line);
       catch (IOException e) {
        InputStream es = connection.getErrorStream();
        InputStreamReader isr = new InputStreamReader(es);
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        try {
        while ( (line = br.readLine()) != null) {
         System.out.println("error: " + line);
        }catch (IOException errio) {
 } }


Message Edited by dimple on 09-13-2006 01:46 AM

Message Edited by dimple on 09-13-2006 05:40 AM

What does a wire capture of your request look like (HTTP headers + soap message) ?


I am using ethereal to get the wire capture but since the connection is HTTPS all the data is encrypted.

Doh !!

Is there any way to see the data ?






Message Edited by dimple on 09-13-2006 01:08 PM


hi, i changed the url from https to http and found out some thing wrong i was doing. fixed that and then i got the below error. You were right that i should use soap tool kit to create the message. So i plan to continue with the soap tool kit to figure out what is going wrong there. Will pick up that tommorrow morning. After this learning I bet that the message format is the problem ... need to play around more.

thanks again, dimple :-)


java.io.IOException: Server returned HTTP response code: 500 for URL: http://www
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
        at URLSample.main(URLSample.java:48)
error: <?xml version="1.0" encoding="UTF-8"?>
error: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope
/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/200
error:  <soapenv:Body>
error:   <soapenv:Fault>
error:    <faultcode>soapenv:Server</faultcode>
error:    <faultstring>org.xml.sax.SAXParseException: Element type &quot;soap:En
velope&quot; must be followed by either attribute specifications, &quot;&gt;&quo
t; or &quot;/&gt;&quot;.</faultstring>
error:    <detail/>
error:   </soapenv:Fault>
error:  </soapenv:Body>
error: </soapenv:Envelope>