通过SQL Server过程使用webservice

时间:2017-07-21 13:34:21

标签: sql-server json web-services

我使用sql server 2016通过商店程序使用webservice。我在JSON中有一个web服务,返回以下内容:

["Name":"Rebecca","email":"rebecca@hotmail.com","ra":"12345"},
{"name":"Caroline","email":"caroline@hotmail.com","ra":"23456"},
{"name":"Vanessa","email":"vanessa@yahoo.com.br","ra":"99999"}]

我可以通过传递变量来消耗它。如果我离开我的webservice接收参数并通过它,我可以返回学生的姓名和电子邮件。但是如果我离开我的webservice而不需要接收参数并删除过程参数pass和execute,我的过程返回null。我需要在代码中更改哪些内容才能返回我的网络服务公开的学生的完整列表?

这是我的代码:

create PROCEDURE webservice_parametros (@RA as varchar (5))
AS
BEGIN

DECLARE @OBJ INT;
DECLARE @URL VARCHAR(200);
DECLARE @RESPONSE VARCHAR(8000);

SET @URL = 'http://dominio:8080/v1/alunos/' + @RA
EXEC SP_OACREATE 'MSXML2.ServerXMLHttp', @OBJ out
EXEC SP_OAMETHOD @OBJ, 'OPEN', NULL, 'GET', @URL, FALSE
EXEC SP_OAMETHOD @OBJ, 'SEND'
exec SP_OAGETPROPERTY @OBJ, 'responseText', @RESPONSE out
EXEC SP_OADESTROY @OBJ

SELECT JSON_VALUE(@RESPONSE, '$.nome') as nome,
       JSON_VALUE(@RESPONSE, '$.email') as email

END     

execute webservice_parametros '12345'

我的代码返回NULL

create PROCEDURE webservice
AS
BEGIN

DECLARE @OBJ INT;
DECLARE @URL VARCHAR(200);
DECLARE @RESPONSE VARCHAR(8000);

SET @URL = 'http://dominio:8080/v1/alunos/'
EXEC SP_OACREATE 'MSXML2.ServerXMLHttp', @OBJ out
EXEC SP_OAMETHOD @OBJ, 'OPEN', NULL, 'GET', @URL, FALSE
EXEC SP_OAMETHOD @OBJ, 'SEND'
exec SP_OAGETPROPERTY @OBJ, 'responseText', @RESPONSE out
EXEC SP_OADESTROY @OBJ

SELECT JSON_VALUE(@RESPONSE, '$.nome') as nome,
       JSON_VALUE(@RESPONSE, '$.email') as email

END     

execute webservice

0 个答案:

没有答案