Page 1 of 1
Call a webservice from switchscripter
Posted: Wed Jul 18, 2012 2:27 pm
by braam
Hi
I want to call a webservice from within Switch Scripter and just pass it a value...the jobname basically.
I managed to be able to call StoredProcedures from within SwitchScripter, which works fantastic.
Does anyone maybe have a sample code that has done this before from within SwitchScripter please?
Just for interest sake, this is how I call the Stored Procedure:
dbStat.execute("rsp_insert_records '" + campaign + "'" + "," + "'" + jobname + "'" + "," + quantity);
dbConn.disconnect();
job.sendToSingle(job.getPath());
Call a webservice from switchscripter
Posted: Wed Jul 18, 2012 2:59 pm
by dkelly
Switch only supports SOAP v1 protocol. Most webservices use HTTP/JSON/WDSL protocol now.
Call a webservice from switchscripter
Posted: Thu Jul 26, 2012 12:39 pm
by caio
Hi
i have this sample to call webserver via SOAP to send mail order:
You have to create SOAP request (url, request, action).
look the manual......
function jobArrived( s : Switch, job : Job )
{
var dataset = job.getDataset('Xml');
var map = dataset.createDefaultMap();
var progressivo = dataset.evalToString ("/field-list/field[tag='myorder']/value", map);
var url = "
http://www.mySite.com/sendop.asmx";
var action = "
http://soapinterop.org/SendMail";
var request =
{
"http://soapinterop.org:SendMail" :
{
"TagsOrder" : "http://soapinterop.org:ID",
"http://soapinterop.org:ID":progressivo} };
var result = SOAP.request(url, request, action);
job.log(1,'Valoreprogressivo='+progressivo)
s.log(-1, "Result: %1",
result[http://soapinterop.org:SendMailResponse][SendMailResult]);
job.sendToSingle(job.getPath())
}
Call a webservice from switchscripter
Posted: Tue Jul 31, 2012 7:09 pm
by jskibbie
I am also struggling with the syntax for a SOAP request. I'm trying to connect to a proofHQ API (
http://api.proofhq.com/home). The documentation says their entry point is "
https://www.proofhq.com/soap". The WSDL is at
https://www.proofhq.com/soap?wsdl
I'm trying to perform the method named "doLogin". It requires two parameters: Login, Password
How do you form the request object portion of: SOAP.request(url, request, action).
I'm assuming the url is "
https://www.proofhq.com/soap", and based on the WSDL, the action is: "
https://www.proofhq.com/doLogin".
Any help in understanding how to form the request object would be greatly appreciated.
Call a webservice from switchscripter
Posted: Tue Aug 28, 2012 7:40 am
by pragmeta
Hey Braam,
Can you send me the stored Procedure call as you use it in the Script.
I'm trying to call a stored procedure from an MySQL database...
Thanks,
Peter
Call a webservice from switchscripter
Posted: Tue Aug 28, 2012 8:21 am
by braam
Hi Peter
sure, here is a sample of a entire script...whats important to note though is that you have to create a ODBC connection to the MYSQL database first on the Switch server. then call that ODBC as your database, you cant call the MYSQL database directly.
Thanks for the replies everyone, I will test it and give feedback once I got it working.
Kind Regards
Herewith a entire script Peter:
function jobArrived( s : Switch, job : Job )
{
var ordernumber = job.getNameProper();
dbConn = new DataSource();
dbConn.connect("XMPIESQLPlatLife","plc","plc247");
if ( dbConn.isConnected() )
{
var len = job.getNameProper().length;
// var campaign = job.getNameProper().left(len - 12);
var campaign = job.getNameProper().left(12);
var jobname = job.getNameProper();
var quantity = job.getNameProper().right(3);
s.log(1,"Database connection succes" + ordernumber + "ja praat" + campaign + " " + jobname + " " + quantity);
dbStat = new Statement(dbConn);
dbStat.execute("rsp_insert_records '" + campaign + "'" + "," + "'" + jobname + "'" + "," + quantity);
dbConn.disconnect();
job.sendToSingle(job.getPath());
}
else
{
s.log(1,"Database connection error");
}
job.sendToSingle(job.getPath());
}