我创建了一个程序,该程序应从Bing的xml数据中检索TravelDistance,但@ResponseText始终为NULL。我能够使其与Google合作,但不能与Bing合作。我已经从Bing API网站上对示例进行了硬编码,可以看到XML和@ServiceUrl,但是
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
为@Object提供一个值,为@ResponseText提供仅NULL
` Declare @Object as Int;
Declare @ResponseText as nvarchar(max);
Declare @serviceUrl as varchar(max)
--set @serviceUrl = 'http://maps.googleapis.com/maps/api/distancematrix/xml?origins=' +@ToAddress+@ToCity+@ToState+@ToPostCode+
-- '&destinations=' +@FromAddress+@FromCity+@FromState+ @FromPostCode +'&mode=driving&language=en-EN&units=imperial;'
set @serviceUrl = 'https://dev.virtualearth.net/REST/v1/Routes/Truck?wp.0=590%20Crane%20Ave%2C%20Pittsburgh%2C%20PA&wp.1=600%20Forbes%20Ave%2C%20Pittsburgh%2C%20PA&vehicleHazardousMaterials=Flammable&output=xml&key=XXXXXXXXXXXXXXXX'
Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',
@serviceUrl, --Your Web Service Url (invoked)
'false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
declare @result table(data text)
Declare @Response as XML
SELECT @Response response, @ResponseText responsetext,@serviceUrl serviceurl
Select @ResponseText as XMLList
SET @Response = CAST(@ResponseText AS XML);
Declare @Status as varchar(20)
Declare @Distance as varchar(20)
Declare @Time as varchar(20)
--
set @Status= @Response.value('(Response/ResourceSets/ResourceSet/Resources/Route/BoundingBox/TravelDistance)[1]', 'varchar(20)')
print @Status
if(@Status='ZERO_RESULTS')
Begin
set @Distance=@Status
End
else
Begin
-- set @Distance=@Response.value('(DistanceMatrixResponse/row/element/distance/text)[1]', 'varchar(20)')
set @Distance=@Response.value('(Response/ResourceSets/ResourceSet/Resources/Route/BoundingBox/TravelDistance)[1]','varchar(20)')
-- set @Time=@Response.value('(DistanceMatrixResponse/row/element/duration/text)[1]', 'varchar(20)')
End
-- Select @Response.value('(DistanceMatrixResponse/row/element/distance/text)[1]', 'varchar(10)') as Distance
-- select (cast(replace(@Distance,' km','') as numeric)/2) + ((cast(replace(@Distance,' km','') as numeric)/2)/4) as Distance, @Time as Time
select @Distance as Distance`
我想念什么?