Stored Procedures Encapsulate Web service

Source: Internet
Author: User

Shang, reprint please keep http://www.cnblogs.com/BinBinGo/p/6959569.html.

SQL can also call the Web service

The steps are as follows:

1 Modifying the configuration

' Show advanced Options ' 1 ; GO RECONFIGURE ; GO  'Ole Automation procedures'1; GO RECONFIGURE ; GO

2 encapsulating the calling procedure in a stored procedure, this is the case of my reference to the German map.

CREATE   PROCFn_et_geocode (@log VARCHAR( -),@lat VARCHAR( -),@result VARCHAR(8000) OUTPUT) as DECLARE @ServiceUrl  as VARCHAR( +); DECLARE @UrlAddress VARCHAR( -);--WebService Address: Start with HTTP, end with Slash, for example ' http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/'SET @UrlAddress = 'http://restapi.amap.com/v3/geocode/';DECLARE @FunName VARCHAR( -);--method name called in WebService: for example ' Getmobilecodeinfo 'SET @FunName = 'Regeo'; --The following parameter corresponds to the [parameter name] of the parameter in WebService.DECLARE @output VARCHAR( -)  , @location VARCHAR( $)  , @key VARCHAR( $)  , @radius VARCHAR(Ten)  , @extensions VARCHAR(Ten);SET @output = 'JSON';SET @location = @log+','+@lat;SET @key = 'xxxxxxxxxxxxxxxx';SET @radius = ' +';SET @extensions = 'Base';SET @ServiceUrl = @UrlAddress + @FunName + '? output=' + @output + '&location='    + @location + '&key=' + @key + '&radius=' + @radius + '&extensions='    + @extensions;
---actually call the following statements, all of which are splicing API addresses. DECLARE @Object as INT;DECLARE @ResponseText as VARCHAR(8000); EXECsp_OACreate'msxml2.xmlhttp',@ObjectOut ;EXECsp_OAMethod@Object,'Open',NULL,'Get',@ServiceUrl,'false';EXECsp_OAMethod@Object,'Send';EXECsp_OAMethod@Object,'ResponseText',@ResponseTextOUTPUT; SET @result = @ResponseText; EXECsp_OADestroy@Object;GO

3 Executing stored procedures

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

Stored Procedures Encapsulate Web service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.