简体   繁体   中英

Calling Web Service periodically

I have implemented a REST API in JAVA. I want to run this periodically, meaning, every week at a specified time. I am trying to automate this by calling web service via SQL server job. I am having trouble setting up this call. Every article I read either suggested it's a bad idea or its way too complicated to comprehend. Can anyone please help with an easy way to set up the call? Or if there are alternatives, which are those?

I have already tried:

Declare @Object as Int;
Declare @ResponseText as Varchar(8000);

Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',
                                                              'http://www.webservicex.com/stockquote.asmx/GetQuote?symbol=MSFT', --Your Web Service Url (invoked)
                                                              'false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT

Select @ResponseText

Exec sp_OADestroy @Object

But I am not sure its safest option.

There are a number of options available to configure a scheduler to periodically invoke a web service call.

Option 1> The simplest one is to use the cURL utility within an linux system and schedule it in crontab entry.

Example invocation: curl -XGET http://www.webservicex.com/stockquote.asmx/GetQuote?symbol=MSFT

Option 2> The second option could is to schedule the wrapper shell script in an Autosys configuration.

Option 3> If you are using a Java ecosystem, we can use the Spring batch scheduling .

I came across another alternative. You can run PowerShell Script in Sql Jobs. I wrote script to call Web Service and Sql Job to run script everyweek. Works perfectly.

Thank You.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM