Achieved the same using SQL CLR.
How to pass SSL certificate to call secured web service in SQL Server 2008 R2
-
05-07-2023 - |
Question
I have an external web service secured by SSL certificate. I can call this web service in my C# application. Now I need to call it using SQL Server 2008 R2. I have used some code to call it like
declare @iobject integer
declare @ihr integer
declare @data nvarchar(4000)
declare @smtpWebService varchar(200)
declare @retVal varchar(8000)
declare @src varchar(1000)
declare @desc varchar(1000)
exec @ihr = sp_oaCreate 'Msxml2.ServerXMLHTTP.3.0', @iobject OUTPUT
if (@ihr <> 0)
begin
exec sp_displayoaerrorinfo @iobject, @ihr return
end
set @smtpWebService = 'https://xyzService.asmx/GetInformation'
set @data = 'ID=50'
exec @ihr = sp_OAMethod @iobject, 'Open', null, 'GET',@smtpWebService, 0
exec @ihr = sp_OAMethod @iobject, 'setRequestHeader', null, 'Content-Type', 'application/x-www-form-urlencoded'
exec @ihr = sp_OAMethod @iobject, 'send', null, @data
if @ihr <> 0
begin
exec sp_OAGetErrorInfo @iobject, @src OUT, @desc OUT
select hr = convert(varbinary(4),@ihr), Source = @src, Description = @desc
print @src
print @desc
end
exec @ihr = sp_OAGetProperty @iObject, 'responseText', @retVal OUT
print @retVal
-- Destroy the object
exec @ihr = sp_OADestroy @iobject
It gives message
A certificate is required to complete client authentication
Can anyone please suggest how I can pass a SSL certificate from SQL Server?
Note: the certificate is installed on my current user account and local machine.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow