sql 存储过程调用webservice
步骤:1.更改全局配置
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
2.安装SoapToolkit(网上现有的方案大多没有提到这步)
http://download.csdn.net/detail/ahywg/3800156
3.SQL直接调用webservice(略去触发器和存储过程)
DECLARE @scid int,@rt int
DECLARE @result nvarchar(4000)
--创建MSSOAP.SoapClient组件(如果安装的是SoapToolkit30,应该是MSSOAP.SoapClient30,否则是MSSOAP.SoapClient),存储到@object中
EXEC @rt=sp_OACreate 'MSSOAP.SoapClient30',@scid out
--'http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl'为webservice地址
--‘qqOnlineWebService’为webservice名称
EXEC @rt = sp_OAMethod @scid, 'mssoapinit',null,'http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl','qqOnlineWebService'
--'qqCheckOnline'为webservice的一个方法,后面跟2个参数(输入参数:QQ号码 String,默认QQ号码:8698053。返回数据:String,Y = 在线;N = 离线;E = QQ号码错误;A = 商业用户验证失败;V = 免费用户超过数量)
EXEC @rt = sp_OAMethod @scid, 'qqCheckOnline', @result OUT,N'8698053'
IF @rt <> 0
BEGIN
EXEC sp_OAGetErrorInfo @scid
END
ELSE
BEGIN
select @result
END
--释放掉@scid
EXEC @rt = sp_OADestroy @scid
GO