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
dimpledimple 

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

HI,
 
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.
 
 
<html>
<head>
<title>XML Client for soap Servlet Example</title>
</head>
<body>
<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
</p>
<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://
www.w3.org/2001/XMLSchema">
      <soap:Body>
         <login xmlns="urn:enterprise.soap.sforce.com">
            <username>dimpjain@yahoo.com</username>
            <password>******</password>
         </login>
      </soap:Body>
 </soap:Envelope>
</textarea> <br>
<input type='submit' value='Send'> | <input type='reset' value='Clear'>
</form>
</body>
</html>
 
 
 
 
RESPONSE -
 
  <?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:exceptionCode>UNKNOWN_EXCEPTION</sf:exceptionCode>
  <sf:exceptionMessage>Destination URL not reset. The URL returned from login must be set in the SforceService</sf:exceptionMessage>
  </sf:fault>
  </detail>
  </soapenv:Fault>
  </soapenv:Body>
  </soapenv:Envelope>
 
 
REGARDS,
DIMPLE :-(
SuperfellSuperfell
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.
dimpledimple
Hi,
 
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 />

<SOAP-ENV:Body>

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

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

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

</login>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

]; 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>

 
 
Code:METHOD A
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");
    username.setValue(uname);
    Element password = new Element("password");
    password.setValue(pwd);
    
    
//  build body 
 SOAPBodyHDOMImpl body = (SOAPBodyHDOMImpl) envelope.createBody(); 
 SOAPActionHDOMImpl action = new SOAPActionHDOMImpl("login"); 
 action.getElement().setNamespace(Namespace.getNamespace("urn:enterprise.soap.sforce.com"));
 action.getElement().addContent(username);
 action.getElement().addContent(password);
 try {
 body.setAction(action);
 }catch(SOAPException e) {
  System.out.println(e.getMessage());
  e.printStackTrace();
 }
 
 
    
    SOAPMessage request = new SOAPMessage(envelope);
    
    


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


    Map m = new HashMap();
    m.put("Cookie", "SMSESSION="+ token);
    m.put("SOAPAction","");
  
    
    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){
      System.out.println(e.getMessage());
     }   
   
     
     
    try {
     loginResponse = client.sendRequest(request);
    } catch(SOAPException e) {
     e.printStackTrace();
     } 
    
 }
 
 public static void main(String args[]) {
  System.setProperty("proxySet","true");
  System.setProperty("https.proxyHost","wwwproxy.ms.com");
  System.setProperty("https.proxyPort","8080");
  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) {
  System.setProperty("https.proxyHost","wwwproxy.ms.com");
   System.setProperty("https.proxyPort","8080");
   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.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("POST");
        
     connection.setRequestProperty("SOAPAction", "\"\"");
   connection.setRequestProperty("Expect", "100-continue");
   connection.setRequestProperty("Content-Type","text/xml; charset=utf-8");
   connection.setRequestProperty("Content-Length","370");
   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:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"");
        //wout.write("xmlns:transport=\"http://schemas.xmlsoap.org/soap/http/\"");
        wout.write("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\r\n");
        wout.write("<soap:Body\r\n");
        wout.write("<login xmlns=\"urn:partner.soap.sforce.com\"\r\n");
        wout.write("<username\rdimpjain@yahoo.com</username\r\n");
        wout.write("<password\r******</password\r\n");
        wout.write("</login\r\n");
        wout.write("</soap:Body\r\n");
        wout.write("</soap:Envelope\r\n");        
        wout.flush();
        wout.close();
    
        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) {
        e.printStackTrace();
        
        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) {
          errio.printStackTrace(); 
        
        }
      }
 } }

 

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

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

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

Hi,

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 ?

Thanks,

Dimple

 

 

 

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

dimpledimple

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
.salesforce.com/services/Soap/c/6.0
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1153)
        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
1/XMLSchema-instance">
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>