SQL调用Webservices
IF NOT object_id('proc_CallWebServices') IS NULL DROP PROCEDURE proc_CallWebServices GO CREATE PROCEDURE proc_CallWebServices( @parametor VARCHAR(20) = NULL ) AS BEGIN DECLARE @obj INT DECLARE @ValordeRegreso int DECLARE @sUrl VARCHAR(200) DECLARE @response VARCHAR(8000) DECLARE @hr INT DECLARE @src VARCHAR(255) DECLARE @desc VARCHAR(255) SET @sUrl = 'http://mys-zhangj06:802/WebService1.asmx/HelloWorld' EXEC sp_OACreate 'MSXML2.ServerXMLHTTP', @obj OUT EXEC sp_OAMethod @obj, 'open',NULL,'GET',@sUrl,false EXEC sp_OAMethod @obj, 'send' EXEC sp_OAMethod @obj, 'responseText',@response OUT SELECT @response [response] EXEC sp_OADestroy @obj RETURN END GO EXEC proc_CallWebServices '' IF NOT object_id('HTTP_POST') IS NULL DROP PROCEDURE HTTP_POST GO CREATE PROCEDURE [dbo].[HTTP_POST] ( @sUrl VARCHAR(500) , @response VARCHAR(500) OUT ) AS BEGIN DECLARE @obj INT , @hr INT , @status INT , @msg VARCHAR(255) EXEC @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT IF @hr <> 0 BEGIN RAISERROR('sp_OACreate MSXML2.ServerXMLHttp.3.0 failed', 16,1) RETURN END EXEC @hr = sp_OAMethod @obj, 'open', NULL, 'POST', @sUrl, false IF @hr <> 0 BEGIN SET @msg='sp_OAMethod Open failed' GOTO eh END EXEC @hr = sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type','application/x-www-form-urlencoded' IF @hr <> 0 BEGIN SET @msg='sp_OAMethod setRequestHeader failed' GOTO eh END EXEC @hr = sp_OAMethod @obj, send, NULL, '' IF @hr <> 0 BEGIN SET @msg='sp_OAMethod Send failed' GOTO eh END EXEC @hr = sp_OAGetProperty @obj, 'status', @status OUT IF @hr <> 0 BEGIN SET @msg='sp_OAMethod read status failed' GOTO eh END IF @status <> 200 BEGIN SET @msg='sp_OAMethod http status '+STR(@status) GOTO eh END EXEC @hr = sp_OAGetProperty @obj, 'responseText', @response OUT IF @hr <> 0 BEGIN SET @msg='sp_OAMethod read response failed' GOTO eh END EXEC @hr = sp_OADestroy @obj RETURN eh: EXEC @hr = sp_OADestroy @obj RAISERROR(@msg, 16, 1) RETURN END GO DECLARE @res VARCHAR(500) EXEC [HTTP_POST] 'http://mys-zhangj06:802/WebService1.asmx/GetTime?date=zzz',@res OUT SELECT @res