I am trying to build a stored procedure in TSQL to call a webservice. I\'ve done this before in Oracle, but it seems like it\'s not so easy in MSSQL. There are of course man
In the past I have used the following method, it may not be the best method these days but it has worked successfully for me :
DECLARE @obj int,
@url VarChar(MAX),
@response VarChar(MAX),
@requestHeader VarChar(MAX),
@requestBody VarChar(MAX)
SET @url = 'http://....'
SET @requestBody = '
...
'
EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
EXEC sp_OAMethod @obj, 'Open', NULL, 'GET', @url, false
EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type', 'text/xml;charset=UTF-8'
EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'SOAPAction', 'POST'
EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Length', LEN(@requestBody)
EXEC sp_OAMethod @obj, 'send', NULL, @requestBody
EXEC sp_OAGetProperty @obj, 'responseText', @response OUT
SELECT @response [RESPONSE]
EXEC sp_OADestroy @obj
I have used this to call a webservice which produces a report and emails it within the method.