You need to sign in to do that
Don't have an account?
Error 500 when calling my Webservice from an s-control
Hi all.
I'm trying to implement a web service (hosted on one of our companies web servers) that can be called from Salesforce to receive license information from our licensing system that should then be stored in SalesForce. So, this is a webservice called from within SalesForce and not the other way around (which judging by the examples I found seems to be the the most common case).
At first I was getting javescript errors due to no sessionId being set for sforce.connection (?) which I was able to debug in Visual Studio. This was resolved by adding a call to sforce.connection.login however I am still getting a http error 500 on the call. It works perfectly fine if called by performing a POST from a stand-alone HTML-page but not from within Salesforce. Am I missing some vital step? Here's my test S-control which requests a specific serial number from the webservice:
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">
sforce.connection.login("john.doe@somecompany.com", "passwordSECURITYTOKEN");
function GetWsSn(){
var envelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> ' +
' <soap:Body> ' +
' <Generate xmlns="http://MyXMLWebServiceNameSpace/"> ' +
' <outSN></outSN> ' +
' <inCountry>1</inCountry> ' +
' <inPartner>1</inPartner> ' +
' <inCount>1</inCount> ' +
' <inPrefix>NSS</inPrefix> ' +
' </Generate> ' +
' </soap:Body> ';
var request = null;sforce.connection.remoteFunction({
url : "http://85.226.44.189/northernweblicex/SerialNumber.asmx",
requestHeaders: {
"Content-Type": "text/xml; charset=utf-8",
"SOAPAction": "http://NorthernWebLicEx.northern.net/Generate"
},
mimeType: "text/xml",
requestData: envelope,
method: "POST",
onSuccess : function(response, _request) {
document.getElementById("result").value = response.GenerateResult;
},
onFailure : function(response, request) {
document.getElementById("result").value = "Failed " + response + "\n" + request.getAllResponseHeaders();
}
});
}</script>
<body>
Country 1 <select id="country1"></select>
Country 2 <select id="country2"></select>
<input type="button" value="Get Rate" onclick="javascript: GetWsSn();" />
<br><br>Results<br>
<textarea rows="10" id="result" cols="80"></textarea>
</body>
Some more info:
- The site hosting the webservice has been added to the remote site list under security settings.