SQL調用WebService介面,sql調用webservice

來源:互聯網
上載者:User

SQL調用WebService介面,sql調用webservice



            今天在做一個很奇葩的東西,中間有個過程要在SQL觸發器裡面調用webservice介面。呵呵~


                   

--調用webService----------------declare @ServiceUrl as varchar(1000) DECLARE @UrlAddress varchar(500)--WebService地址:以http開頭,結尾帶斜杠,例如'http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/' set @UrlAddress = 'http://api.map.baidu.com/telematics/v3/weather?location=%E5%8C%97%E4%BA%AC&output=json&ak=6brZIzYakoTEW1xrDYk0Wqhd 'SET @ServiceUrl=@UrlAddress--如果有參數可以在此處拼入--訪問地址擷取結果Declare @Object as IntDeclare @ResponseText as Varchar(8000) --必須8000                  EXEC sp_OACreate 'MSXML2.XMLHTTP', @Object OUT; --建立OLE組件對象Exec sp_OAMethod @Object, 'open', NULL, 'POST',@ServiceUrl,'false' --開啟連結,注意是get還是postExec sp_OAMethod @Object, 'send'EXEC sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT --輸出參數     Select @ResponseText      --輸出結果Exec sp_OADestroy @ObjectGO


               這裡的webservice只是百度提供的一個測試介面,真正用到的時候,我們可以自己寫介面,然後調用自己寫的介面,遠程執行方法。









著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.