Can you call a webservice from TSQL code?

前端 未结 9 1812
野趣味
野趣味 2020-11-29 00:39

Is there a way to call out from a TSQL stored procedure or function to a webservice?

9条回答
  •  执念已碎
    2020-11-29 01:04

    Yes , you can create like this

    CREATE PROCEDURE CALLWEBSERVICE(@Para1 ,@Para2)
    AS
    BEGIN
        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','false'
        Exec sp_OAMethod @Object, 'send'
        Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
        Select @ResponseText
        Exec sp_OADestroy @Object
    END
    

提交回复
热议问题