預存程序封裝web service

來源:互聯網
上載者:User

標籤:url   roc   obj   varchar   char   tom   name   text   json   

卞功鑫  ,轉載請保留http://www.cnblogs.com/BinBinGo/p/6959569.html。

sql 也可以調用web service

步驟如下:

 

1 修改配置

sp_configure ‘show advanced options‘, 1;GORECONFIGURE;GOsp_configure ‘Ole Automation Procedures‘, 1;GORECONFIGURE;GO

 

 

2 把調用過程封裝在預存程序中,這是我引用高德地圖的案例 

 

CREATE   PROC fn_et_geocode(@log VARCHAR(20),@lat VARCHAR(20),@result VARCHAR(8000) OUTPUT)as DECLARE @ServiceUrl AS VARCHAR(1000); DECLARE @UrlAddress VARCHAR(500);--WebService地址:以http開頭,結尾帶斜杠,例如‘http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/‘ SET @UrlAddress = ‘http://restapi.amap.com/v3/geocode/‘;DECLARE @FunName VARCHAR(50);--WebService中調用的方法名:例如‘getMobileCodeInfo‘SET @FunName = ‘regeo‘;   --以下參數對應WebService中參數的[參數名]DECLARE @output VARCHAR(20)  , @location VARCHAR(200)  , @key VARCHAR(200)  , @radius VARCHAR(10)  , @extensions VARCHAR(10);SET @output = ‘json‘;SET @location = @log+‘,‘+@lat;SET @key = ‘xxxxxxxxxxxxxxxx‘;SET @radius = ‘1000‘;SET @extensions = ‘base‘;SET @ServiceUrl = @UrlAddress + @FunName + ‘?output=‘ + @output + ‘&location=‘    + @location + ‘&key=‘ + @key + ‘&radius=‘ + @radius + ‘&extensions=‘    + @extensions;                     
--- 真正調用的是下面的這些語句,上面的都是拼接API地址. DECLARE @Object AS INT;DECLARE @ResponseText AS VARCHAR(8000); EXEC sp_OACreate ‘MSXML2.XMLHTTP‘, @Object OUT;EXEC sp_OAMethod @Object, ‘open‘, NULL, ‘get‘,@ServiceUrl, ‘false‘;EXEC sp_OAMethod @Object, ‘send‘;EXEC sp_OAMethod @Object, ‘responseText‘, @ResponseText OUTPUT; SET @result = @ResponseText; EXEC sp_OADestroy @Object;GO

 

 

 

3  執行預存程序

 

DECLARE @geojson VARCHAR(8000)EXEC fn_et_geocode ‘113.14052842882‘,‘27.81207139757‘,@geojson OUTPUTSELECT @geojson

 

預存程序封裝web service

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.