2011. 8. 5. 10:51

SQL서버에서 WebService 호출

원래 트리거에서 호출해 볼까 했는데,
그건 다들 절대로 하지 말라는 분위기임

일단, 아직 적용을 안해봤기 때문에 아래 소스가 돌아갈지 여부는 잘 모르겠음
외국의 포럼에서 긁어온 소스인데, 돌아갈지 여부는 뭐...나중에 확인 후 수정 예정

아래의 소스를 실행하기 위해선 OLE Automation 옵션을 활성화 시켜야 한다고 함
활성화 방법은


For SQL Server 2005 you have to enable the "OLE Automation" option.
Start-> Programs - > Microsoft SQL Server 2005 -> Configuration Tools ->SQL Server Surface Area Configuration
Click the link Surface Area Configuration for Features
Expand the DB -> Database Engine
Select OLE Automation & Check the checkbox Enable OLE Automation..

-------------------------------------------------------------------------------------------
쿼리로 실행하는 법

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO 

이렇게 호출하면 활성화 됨.(물론 처음 세팅할때만) 



이렇게 써 있었음...;; 아직 안해봐서.. -_-);
일단 정보를 위해서 보관용으로;;

로컬에 설치된 SQL Server 2008 Express R2로 확인해 본 결과
정상 동작함(물론 위의 설정 쿼리를 한번 돌려준 상태임)

Declare @Object as Int;
Declare @ResponseText as Varchar(8000);
 
Code Snippet
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get','http://www.webservicex.com/stockquote.asmx/GetQuote?symbol=MSFT','false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
 
Select @ResponseText
 
Exec