缺少Webservice根元素

时间:2014-03-26 12:40:24

标签: sql sql-server-2008 stored-procedures

我试图从vs management studio 2012中的存储过程调用web服务。 这是我尝试调用

的网络服务
 http://www.webservicex.net/globalweather.asmx?op=GetWeather

这里有你的存储过程

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE CallWeatherService
-- Add the parameters for the stored procedure here
 @Country varchar(20) = null,
 @City varchar(20) = null
AS

BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
DECLARE @obj INT
DECLARE @response varchar(8000)
DECLARE @serviceUrl VARCHAR(200)



SET NOCOUNT ON;
SET @serviceUrl = 'http://www.webservicex.net/globalweather.asmx?CityName?Param1=' + @City + '&CountryName?Param2=' + @Country + '' 

EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
EXEC sp_OAMethod @obj, 'Open', NULL, 'POST', @serviceUrl, false
EXEC sp_OAMethod @obj, 'send'
EXEC sp_OAGetProperty @obj, 'responseText', @response OUT


-- Insert statements for procedure here
SELECT @response [response]
EXEC sp_OADestroy @obj
END
GO

我调用我的存储过程:

USE [testdatabase]
GO

DECLARE @return_value int

EXEC    @return_value = [dbo].[CallWeatherService]
    @Country = N'Belgium',
    @City = N'Koksijde'

SELECT  'Return Value' = @return_value

GO

然而我收到错误

 System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Root element is missing.

知道我做错了吗?

0 个答案:

没有答案