You need to sign in to do that
Don't have an account?

calling apex generated Webservice in s-control
Hi,
I have webservice written in .net located on my machine (I could see the web page located in same directory from URL type s-control in salesforce. so that means salesforce can access the files from that directory.) I generated APex class from the WSDL(had to remove soap12 bindings).
//Generated by wsdl2apex
public class tempuriOrg {
public class HelloWorld_element {
public String arg;
private String[] arg_type_info = new String[]{'arg','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
private String[] field_order_type_info = new String[]{'arg'};
}
public class testSalesForceSoap {
public String endpoint_x = 'http://machineName/virtualdirectoryname/testSalesForce.asmx';
private String[] ns_map_type_info = new String[]{'http://tempuri.org/', 'tempuriOrg'};
public class HelloWorld_element {
public String arg;
private String[] arg_type_info = new String[]{'arg','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
private String[] field_order_type_info = new String[]{'arg'};
}
public class testSalesForceSoap {
public String endpoint_x = 'http://machineName/virtualdirectoryname/testSalesForce.asmx';
private String[] ns_map_type_info = new String[]{'http://tempuri.org/', 'tempuriOrg'};
public String HelloWorld(String arg) {
tempuriOrg.HelloWorld_element request_x = new tempuriOrg.HelloWorld_element();
tempuriOrg.HelloWorldResponse_element response_x;
request_x.arg = arg;
Map<String, tempuriOrg.HelloWorldResponse_element> response_map_x = new Map<String, tempuriOrg.HelloWorldResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'http://tempuri.org/HelloWorld',
'http://tempuri.org/',
'HelloWorld',
'http://tempuri.org/',
'HelloWorldResponse',
'tempuriOrg.HelloWorldResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.HelloWorldResult;
}
}
public class HelloWorldResponse_element {
public String HelloWorldResult;
private String[] HelloWorldResult_type_info = new String[]{'HelloWorldResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
private String[] field_order_type_info = new String[]{'HelloWorldResult'};
}
}
tempuriOrg.HelloWorld_element request_x = new tempuriOrg.HelloWorld_element();
tempuriOrg.HelloWorldResponse_element response_x;
request_x.arg = arg;
Map<String, tempuriOrg.HelloWorldResponse_element> response_map_x = new Map<String, tempuriOrg.HelloWorldResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'http://tempuri.org/HelloWorld',
'http://tempuri.org/',
'HelloWorld',
'http://tempuri.org/',
'HelloWorldResponse',
'tempuriOrg.HelloWorldResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.HelloWorldResult;
}
}
public class HelloWorldResponse_element {
public String HelloWorldResult;
private String[] HelloWorldResult_type_info = new String[]{'HelloWorldResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
private String[] field_order_type_info = new String[]{'HelloWorldResult'};
}
}
then I wrote wrapper apex class to call the apex code generated.
global class testSalesforce{
WebService static string test1(string name) {
tempuriOrg.testSalesForceSoap soap = new tempuriOrg.testSalesForceSoap();
return soap.HelloWorld('hello world !!! ' + name);}}
Then I created s-control to call this new webservice.
<html>
<head>
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/10.0/connection.js"></script>
<script src="/soap/ajax/10.0/apex.js"></script>
<script>
function X() {
try{
var result = sforce.apex.execute("testSalesforce" ,"test1", {arg:" hello"});
}
catch (ex)
{
alert ("Failed : " + ex);
}
<head>
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/10.0/connection.js"></script>
<script src="/soap/ajax/10.0/apex.js"></script>
<script>
function X() {
try{
var result = sforce.apex.execute("testSalesforce" ,"test1", {arg:" hello"});
}
catch (ex)
{
alert ("Failed : " + ex);
}
}
</script>
</script>
</head>
<body onload=X()>
<div id=userNameArea></div>
<body onload=X()>
<div id=userNameArea></div>
</body>
</html>
</html>
In security controls/remote site settings I have http://machinename url provided.
I am invoking the s-control on custom button click. when I give machinename in endpoint_x, I am getting:
System.CalloutException: Web service
callout failed: Unexpected element. Parser was expecting element
'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
callout failed: Unexpected element. Parser was expecting element
'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
and when I give ip address in endpoint_x and remote site settings I am getting :
IO Exception: Read Timed out
What do I need to do to get it working?
Thanks,
Message Edited by NewToSF on 04-01-2008 11:52 AM
I also want to put my Web sevice on public server but have very little idea about that.
And not able to access Web Service from client machine.
Would you like to help me in order to know the steps to follow to do same.
Thanks in advance.
All Answers
If you tell me what your machine name/ipaddress is, I will be able to check.
You can check it for userself using this site:
http://network-tools.com/default.asp?prog=ping&host=
I have two doubts and would require your help and expertise on that.
1. Can a class with webservice methods be invoked using a trigger.
2. Is there any other way that we can deploy a web service such that it is accessible by Salesforce, other then the Global IP way.
In the above code, I have written a class to create a Account and Update a account, but i am clueless to test the webservice.
can anyone can help me with this
Many Thanks in Advance.
Angel
I also want to put my Web sevice on public server but have very little idea about that.
And not able to access Web Service from client machine.
Would you like to help me in order to know the steps to follow to do same.
Thanks in advance.
I have the a slightly different issue but the same error with this.
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>System.CalloutException: IO Exception: Read timed out
Class.placeOrderSubject: line 151, column 13
Class.placeOrder: line 65, column 20</faultstring></soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
The issue is, the server did return a response but slow. and SF's side timed out before we could recieve the response and treat it as a failed case.
Any solution to increase the callout timeout limit?
any advise is appreciated.
thks!
Lynn