存储过程中调用webservice

存储过程中调用webservice其实是在数据库中利用系统函数调用OLE.

1.查找webservice api 可得到MSSOAP.SoapClient。

2.查找API 接口可得到mssoapinit 方法。

3.查找数据库中执行OLE函数sp_OACreate、sp_OAMethod、sp_OADestroy。

到这里基本就完成了,下面是完整的存储过程。

--set SoapClient to be work
sp_configure 'Ole Automation Procedures',1 
reconfigure 
go 


DECLARE @object int
DECLARE @hr int
DECLARE @result int
DECLARE @objectResult nvarchar(255)

--sp_OACreate see more. http://msdn.microsoft.com/en-in/library/ms189763.aspx
EXEC @hr = sp_OACreate 'MSSOAP.SoapClient', @object OUT
EXEC @hr = sp_OAMethod @object, 'mssoapinit', null, 'http://localhost:52607/WebService1.asmx?WSDL','WebService1'
EXEC @hr = sp_OAMethod @object,'HelloWorld',@objectResult OUT

print @hr

IF @hr <> 0
BEGIN
  EXEC sp_OAGetErrorInfo @object   
  print @object
END
ELSE
BEGIN
 print @objectResult
end
EXEC @hr = sp_OADestroy @object
GO

  

转载于:https://www.cnblogs.com/Alenliu/p/5159857.html

猜你喜欢

转载自blog.csdn.net/weixin_33802505/article/details/93470088