Call a webservice from switchscripter

Post Reply
braam
Newbie
Posts: 7
Joined: Wed Aug 31, 2011 11:28 am

Call a webservice from switchscripter

Post 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());
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Call a webservice from switchscripter

Post by dkelly »

Switch only supports SOAP v1 protocol. Most webservices use HTTP/JSON/WDSL protocol now.
caio
Newbie
Posts: 13
Joined: Tue Mar 22, 2011 8:27 am

Call a webservice from switchscripter

Post 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())

}
jskibbie
Newbie
Posts: 10
Joined: Mon Jan 23, 2012 8:34 pm

Call a webservice from switchscripter

Post 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.
pragmeta
Newbie
Posts: 2
Joined: Sat Jul 02, 2011 12:16 pm

Call a webservice from switchscripter

Post 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
braam
Newbie
Posts: 7
Joined: Wed Aug 31, 2011 11:28 am

Call a webservice from switchscripter

Post 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());









}
Post Reply