You need to sign in to do that
Don't have an account?
SOAP Login 1113 / ASP
Perhaps I'm just dull, but I can't get a propper login working to save my life. My server is Win2K SP3/IIS/ASP/VBScript. I'm using the code below to make my SOAP query:
sforceSoapServer = "https://www.salesforce.com/servlet/servlet.Api"
sforceSoapHeader = "<soap-env:Envelope xmlns:soap-env=""http://schemas.xmlsoap.org/soap/envelope/""" _
& " xmlns:tns=""salesforce"" xmlns:types=""salesforce/encodedTypes"" "_
& " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "_
& " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> " _
& " soap-env:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> " _
& " <soap-env:Header> " _
& " <headerStruct>" _
& " <version xsi:type=""xsd:string"">2.0</version>" _
& " <headerStruct>" _
& " </soap-env:Header>"
sforceSoapFooter = "</soap-env:Envelope>"
strSoapBody = "<soap-env:Body> "
strSoapBody = strSoapBody & "<tns:login xmlns:tns=""sfconnector:SalesforceConnector"" type=""methodCall"">"
strSoapBody = strSoapBody & "<username type=""string"">" & strUsername & "</username>"
strSoapBody = strSoapBody & "<password type=""string"">" & strPassword & "</password>"
strSoapBody = strSoapBody & "</tns:login>"
strSoapBody = strSoapBody & "</soap-env:Body>"
strSoapRequest = sforceSoapHeader & strSoapBody & sforceSoapFooter
'Build the SOAP header
Set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
xmlhttp.Open "POST", sforceSoapServer , False 'False = do not respond immediately
xmlhttp.setRequestHeader "Man", POST & " " & sforceSoapServer & " HTTP/1.1"
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.setRequestHeader "Accept-Encoding", "gzip, deflate"
xmlhttp.setRequestHeader "PrettyPrint", "Yes"
'Send the SOAP request
xmlhttp.send(strSoapRequest)
The response that I get back from the server is always the same:
<?xml version="1.0" encoding="UTF-8" ?><methodResponse><fault><value><struct><member><name>faultString</name><value>unknown method name null</value></member><member><name>faultCode</name><value><int>1113</int></value></member></struct></value></fault></methodResponse>
Any ideas?
Hi Matt,
You're not dull, you are just a very astute documentation reader. There is an omission in the current documentation with regards to the url at which to direct the soap messages. Just change the value of sforceSoapServer to https://www.salesforce.com/servlet/servlet.soapapi. The documentation incorrectly (for SOAP) states https://www.salesforce.com/servlet/servlet.api. servlet.api is for xml-rpc calls, servlet.soapapi is for SOAP.
Also, just to be sure, you should format the message a bit differently wrt the types. Here is a well-formatted, working (if you put values in) login request.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="salesforce" xmlns:types="salesforce/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<q1:login xmlns:q1="sfconnector:SalesforceConnector">
<version xsi:type="xsd:string"></version>
<username xsi:type="xsd:string"></username>
<password xsi:type="xsd:string"></password>
<secure xsi:type="xsd:boolean"></secure>
<remoteApplication xsi:type="xsd:string"></remoteApplication>
</q1:login>
</soap:Body>
</soap:Envelope>
Great! I'm working now. I'm not sure who's end it is broken on, but the 'deflate' header is not working between us (xmlhttp.setRequestHeader "Accept-Encoding", "gzip, deflate") breaks me.
For future reference, this connection command works from ASP/VBScript on IIS 5.0 (Win2K SP3):
sforceSoapServer = "https://www.salesforce.com/servlet/servlet.SoapApi"
'Build the SOAP header
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "POST", sforceSoapServer , False 'False = do not respond immediately
xmlhttp.setRequestHeader "Man", POST & " " & sforceSoapServer & " HTTP/1.1"
xmlhttp.setRequestHeader "Content-Type", "text/xml"
'Send the SOAP request
xmlhttp.send(strSoapRequest)
Sorry to join the pary late, but I'm very intersted in getting this API to work for me via ASP/VBScript.
I have tried the code from this posting, and I'm continuing to have problems.
If I use this address:https://www.salesforce.com/servlet/servlet.SoapApi
responseText returns this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="salesforce" xmlns:types="salesforce/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><soap:Header/><soap:Body><soap:Fault><faultcode>1113</faultcode><faultstring>unknown method name null</faultstring></soap:Fault></soap:Body></soap:Envelope>
If I use this address: https://www.salesforce.com/servlet/servlet.soapapi
responseText returns formatted HTML with the following title:
URL No Longer Exists (404 Error)
I'm assuming there are case sensitivity issues with the address, but I'm not sure what is correct. Can anyone provide advice?
Thanks.
Hi Rich,
Are you trying to do an http get on that address? The reason I ask is that if you paste the url into the address bar in your browser you will get that response. You cannot access the sforce API using http get.
A typical http header for a successful api call is shown below:
POST /servlet/servlet.SoapApi HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.1
Host: www.salesforce.com
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: "sfconnector:SalesforceConnector#login"
Content-Length: 691
Notice the POST and the target (/servlet/servlet.SoapApi) and the Host: www.salesforce.com.
If you wouldn't mind posting the code to invoke the API call we could probably come up with a more specific answer for your implementation.
NOTE: Using VB6 ans MSXML to excercise the API is difficult due to the default formatting of outbound SOAP message by MSXML.
Here's all of the code in a very simple login request I'm attempting to make. It's basically just a copy of mtmatt's code - all ASP/VBScript, no VB6.
Thanks for the help, Dave.
<%@ Language=VBScript %>
<%
strUsername = [username]
strPassword = [password]
'sforceSoapServer = "https://www.salesforce.com/servlet/servlet.Api"
sforceSoapServer = "https://www.salesforce.com/servlet/servlet.soapapi"
'sforceSoapServer = "https://www.salesforce.com/servlet/servlet.SoapApi"
sforceSoapHeader = "<soap-env:Envelope xmlns:soap-env=""http://schemas.xmlsoap.org/soap/envelope/"""
sforceSoapHeader = sforceSoapHeader & " xmlns:tns=""salesforce"" xmlns:types=""salesforce/encodedTypes"" "
sforceSoapHeader = sforceSoapHeader & " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
sforceSoapHeader = sforceSoapHeader & " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> "
sforceSoapHeader = sforceSoapHeader & " soap-env:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> "
sforceSoapHeader = sforceSoapHeader & " <soap-env:Header> "
sforceSoapHeader = sforceSoapHeader & " <headerStruct>"
sforceSoapHeader = sforceSoapHeader & " <version xsi:type=""xsd:string"">2.0</version>"
sforceSoapHeader = sforceSoapHeader & " <headerStruct>"
sforceSoapHeader = sforceSoapHeader & " </soap-env:Header>"
sforceSoapFooter = "</soap-env:Envelope>"
strSoapBody = "<soap-env:Body> "
strSoapBody = strSoapBody & "<tns:login xmlns:tns=""sfconnector:SalesforceConnector"" type=""methodCall"">"
strSoapBody = strSoapBody & "<username type=""string"">" & strUsername & "</username>"
strSoapBody = strSoapBody & "<password type=""string"">" & strPassword & "</password>"
strSoapBody = strSoapBody & "</tns:login>"
strSoapBody = strSoapBody & "</soap-env:Body>"
strSoapRequest = sforceSoapHeader & strSoapBody & sforceSoapFooter
'Build the SOAP header
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP")
xmlhttp.open "POST", sforceSoapServer, False 'False = do not respond immediately
xmlhttp.setRequestHeader "Man", POST & " " & sforceSoapServer & " HTTP/1.1"
xmlhttp.setRequestHeader "Content-Type", "text/xml"
'Send the SOAP request
xmlhttp.send (strSoapRequest)
response.write (xmlhttp.responseText)
%> " sforceSoapHeader = sforceSoapHeader & " soap-env:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> " sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " 2.0" sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " " sforceSoapFooter = "" strSoapBody = " " strSoapBody = strSoapBody & "" strSoapBody = strSoapBody & "" & strUsername & "" strSoapBody = strSoapBody & "" & strPassword & "" strSoapBody = strSoapBody & "" strSoapBody = strSoapBody & "" strSoapRequest = sforceSoapHeader & strSoapBody & sforceSoapFooter 'Build the SOAP header Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP") xmlhttp.open "POST", sforceSoapServer, False 'False = do not respond immediately xmlhttp.setRequestHeader "Man", POST & " " & sforceSoapServer & " HTTP/1.1" xmlhttp.setRequestHeader "Content-Type", "text/xml" 'Send the SOAP request xmlhttp.send (strSoapRequest) response.write (xmlhttp.responseText) %> " sforceSoapHeader = sforceSoapHeader & " soap-env:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> " sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " 2.0" sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " " sforceSoapFooter = "" strSoapBody = " " strSoapBody = strSoapBody & "" strSoapBody = strSoapBody & "" & strUsername & "" strSoapBody = strSoapBody & "" & strPassword & "" strSoapBody = strSoapBody & "" strSoapBody = strSoapBody & "" strSoapRequest = sforceSoapHeader & strSoapBody & sforceSoapFooter 'Build the SOAP header Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP") xmlhttp.open "POST", sforceSoapServer, False 'False = do not respond immediately xmlhttp.setRequestHeader "Man", POST & " " & sforceSoapServer & " HTTP/1.1" xmlhttp.setRequestHeader "Content-Type", "text/xml" 'Send the SOAP request xmlhttp.send (strSoapRequest) response.write (xmlhttp.responseText) %> " sforceSoapHeader = sforceSoapHeader & " soap-env:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> " sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " 2.0" sforceSoapHeader = sforceSoapHeader & " " sforceSoapHeader = sforceSoapHeader & " " sforceSoapFooter = "" strSoapBody = " " strSoapBody = strSoapBody & "" strSoapBody = strSoapBody & "" & strUsername & "" strSoapBody = strSoapBody & "" & strPassword & "" strSoapBody = strSoapBody & "" strSoapBody = strSoapBody & "" strSoapRequest = sforceSoapHeader & strSoapBody & sforceSoapFooter 'Build the SOAP header Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP") xmlhttp.open "POST", sforceSoapServer, False 'False = do not respond immediately xmlhttp.setRequestHeader "Man", POST & " " & sforceSoapServer & " HTTP/1.1" xmlhttp.setRequestHeader "Content-Type", "text/xml" 'Send the SOAP request xmlhttp.send (strSoapRequest) response.write (xmlhttp.responseText) %>
Hi Rich,
Fact is, you can cut and past your vbscript into a VB6 project but not a VB.Net. Defacto, if it's not .Net it's VB6, script or not.
To my chagrin, it seems that you need to use the proper case in the url: sforceSoapServer = "http://localhost:8082/servlet/servlet.SoapApi", for vbscript. But this is not the only problem. The bigger problem is that the soap header is munged. In particular there is an extra > before the end of the soap-env:Envelope tag. This is commonly none as not a well-formed xml document and will never get processed, much less understood at the service end. Since you are hand coding this message, you should always run it through a SOAP parser for well-formedness. It will prevent hours of head scratching. While your at it, you should change the soap-env alias to soap like this:
sforceSoapHeader = "<soap-env: Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"""
There is a fix going out tomorrow to make this change unnecessary.
Next, the login method does not require the headerStruct. And finally, since we are removing the headerStruct from the message we need to move the version down into the method parameters. So you message should look like
sforceSoapServer = "https://www.salesforce.com/servlet/servlet.SoapApi"
sforceSoapHeader = "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"""
sforceSoapHeader = sforceSoapHeader & " xmlns:tns=""salesforce"" xmlns:types=""salesforce/encodedTypes"" "
sforceSoapHeader = sforceSoapHeader & " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
sforceSoapHeader = sforceSoapHeader & " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> "
sforceSoapHeader = sforceSoapHeader & " soap:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> "
sforceSoapHeader = sforceSoapHeader & " </soap:Header>"
sforceSoapFooter = "</soap:Envelope>"
strSoapBody = "<soap:Body> "
strSoapBody = strSoapBody & "<tns:login xmlns:tns=""sfconnector:SalesforceConnector"" type=""methodCall"">"
strSoapBody = strSoapBody & "<version type=""string"">2.0</version>"
strSoapBody = strSoapBody & "<username type=""string"">" & strUsername & "</username>"
strSoapBody = strSoapBody & "<password type=""string"">" & strPassword & "</password>"
strSoapBody = strSoapBody & "</tns:login>"
strSoapBody = strSoapBody & "</soap:Body>"
This version works:
strUsername = ""
strPassword = ""
sforceSoapServer = "https://www.salesforce.com/servlet/servlet.SoapApi"
sforceSoapHeader = "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"""
sforceSoapHeader = sforceSoapHeader & " xmlns:tns=""salesforce"" xmlns:types=""salesforce/encodedTypes"" "
sforceSoapHeader = sforceSoapHeader & " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
sforceSoapHeader = sforceSoapHeader & " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
sforceSoapHeader = sforceSoapHeader & " soap:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""> "
sforceSoapFooter = "</soap:Envelope>"
strSoapBody = "<soap:Body> "
strSoapBody = strSoapBody & "<tns:login xmlns:tns=""sfconnector:SalesforceConnector"" type=""methodCall"">"
strSoapBody = strSoapBody & "<version xsi:type=""xsd:string"">2.0</version>"
strSoapBody = strSoapBody & "<username type=""string"">" & strUsername & "</username>"
strSoapBody = strSoapBody & "<password type=""string"">" & strPassword & "</password>"
strSoapBody = strSoapBody & "</tns:login>"
strSoapBody = strSoapBody & "</soap:Body>"
strSoapRequest = sforceSoapHeader & strSoapBody & sforceSoapFooter
'Build the SOAP header
Set XMLHTTP = CreateObject("Msxml2.ServerXMLHTTP")
XMLHTTP.open "POST", sforceSoapServer, False 'False = do not respond immediately
XMLHTTP.setRequestHeader "Man", POST & " " & sforceSoapServer & " HTTP/1.1"
XMLHTTP.setRequestHeader "Content-Type", "text/xml"
'Send the SOAP request
XMLHTTP.send (strSoapRequest)
Message Edited by DevAngel on 07-03-2003 02:09 PM
Hi,
Just one question to all who submitted that code:
What value did you expect from th evariable POST in the line:
XMLHTTP.setRequestHeader "Man", POST & " " & sforceSoapServer & " HTTP/1.1" ?
--Best Regards,
Rafi E.