AwdbWebServiceSoapBinding / getForecastEquations
ASP AutoIt C C (Unicode) C++ C++ (Unicode) C# DataFlex Delphi Foxpro Go Java Node.js Objective-C Perl PHP Extension PowerBuilder Powershell PureBasic Python CkPython Ruby SQL Server Swift TCL VB.NET VB6 VBScript Xojo
-- Important: See this note about {{-https://cknotes.com/sql-sp_oamethod-string-length-return-value-limitations/|||string length limitations for strings returned by sp_OAMethod calls-}}.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the {{-https://www.example-code.com/sql/default.asp|||warning about using nvarchar(max)-}}.
DECLARE @sTmp0 nvarchar(4000)
DECLARE @xml int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Xml', @xml OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @xml, 'Tag', 'soapenv:Envelope'
DECLARE @success int
EXEC sp_OAMethod @xml, 'AddAttribute', @success OUT, 'xmlns:awd', 'http://www.wcc.nrcs.usda.gov/ns/awdbWebService'
EXEC sp_OAMethod @xml, 'AddAttribute', @success OUT, 'xmlns:soapenv', 'http://schemas.xmlsoap.org/soap/envelope/'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'soapenv:Header', ''
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'soapenv:Body|awd:getForecastEquations|awd:stationTriplet', 'string'
-- In a SOAP HTTP request, including the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) in the XML body is generally not required.
EXEC sp_OASetProperty @xml, 'EmitXmlDecl', 0
DECLARE @soapRequestBody nvarchar(4000)
EXEC sp_OAMethod @xml, 'GetXml', @soapRequestBody OUT
DECLARE @endpoint nvarchar(4000)
SELECT @endpoint = 'https://wcc.sc.egov.usda.gov/awdbWebService/services'
DECLARE @soapAction nvarchar(4000)
SELECT @soapAction = ''
-- For SOAP requests, the standard Content-Type is usually set to "text/xml" or "application/soap+xml"
DECLARE @contentType nvarchar(4000)
SELECT @contentType = 'text/xml'
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
EXEC sp_OAMethod @http, 'ClearHeaders', NULL
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', @contentType
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'SOAPAction', @soapAction
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostXml', @resp OUT, @endpoint, @soapRequestBody, 'utf-8'
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed to send SOAP request.'
EXEC @hr = sp_OADestroy @xml
EXEC @hr = sp_OADestroy @http
RETURN
END
-- Get the XML response body.
DECLARE @responseXml int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Xml', @responseXml OUT
EXEC sp_OAMethod @resp, 'GetBodyXml', @success OUT, @responseXml
DECLARE @statusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @statusCode OUT
PRINT 'response status code: ' + @statusCode
EXEC @hr = sp_OADestroy @resp
-- If the status code does not indicate succcess, then show the response XML,
-- which probably contains error information.
IF @statusCode <> 200
BEGIN
EXEC sp_OAMethod @responseXml, 'GetXml', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @xml
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @responseXml
RETURN
END
EXEC sp_OAMethod @responseXml, 'GetXml', @sTmp0 OUT
PRINT @sTmp0
-- Parse the successful SOAP response XML.
-- This is a sample of the response XML, but the namespace prefixes will be different.
-- We can parse the result using "*" for the namespace prefixes (see below).
DECLARE @comment nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @comment OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:comment'
DECLARE @dataSource nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @dataSource OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:dataSource'
DECLARE @elementCd nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @elementCd OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:elementCd'
DECLARE @coefficient nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @coefficient OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:coefficient'
DECLARE @dataPeriodDays nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @dataPeriodDays OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:dataPeriodDays'
DECLARE @dataPeriodMonth nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @dataPeriodMonth OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:dataPeriodMonth'
DECLARE @dataYearFlag nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @dataYearFlag OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:dataYearFlag'
DECLARE @beginDate nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @beginDate OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:beginDate'
DECLARE @dataPrecision int
EXEC sp_OAMethod @responseXml, 'GetChildIntValue', @dataPrecision OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:dataPrecision'
DECLARE @duration nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @duration OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:duration'
EXEC sp_OAMethod @responseXml, 'GetChildContent', @elementCd OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:elementCd'
DECLARE @endDate nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @endDate OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:endDate'
DECLARE @unitCd nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @unitCd OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:heightDepth|*:unitCd'
DECLARE @value nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @value OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:heightDepth|*:value'
DECLARE @ordinal int
EXEC sp_OAMethod @responseXml, 'GetChildIntValue', @ordinal OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:ordinal'
DECLARE @originalUnitCd nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @originalUnitCd OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:originalUnitCd'
DECLARE @stationTriplet nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @stationTriplet OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:stationTriplet'
DECLARE @storedUnitCd nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @storedUnitCd OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:stationElement|*:storedUnitCd'
EXEC sp_OAMethod @responseXml, 'GetChildContent', @unitCd OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:unitCd'
DECLARE @upstreamForecast nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @upstreamForecast OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:equationTerms|*:upstreamForecast'
DECLARE @footnotes nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @footnotes OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:footnotes'
DECLARE @forecastCondition nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @forecastCondition OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:forecastCondition'
DECLARE @forecastPeriod nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @forecastPeriod OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:forecastPeriod'
DECLARE @forecastType nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @forecastType OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:forecastType'
DECLARE @v_function nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @v_function OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:function'
DECLARE @functionArgument nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @functionArgument OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:functionArgument'
DECLARE @interceptConstant nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @interceptConstant OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:interceptConstant'
DECLARE @key int
EXEC sp_OAMethod @responseXml, 'GetChildIntValue', @key OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:key'
DECLARE @maxOfRecord nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @maxOfRecord OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:maxOfRecord'
DECLARE @minOfRecord nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @minOfRecord OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:minOfRecord'
DECLARE @monthlyCorrelationCoefficients nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @monthlyCorrelationCoefficients OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:monthlyCorrelationCoefficients'
DECLARE @monthlyStderrValues nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @monthlyStderrValues OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:monthlyStderrValues'
DECLARE @name nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @name OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:name'
DECLARE @day int
EXEC sp_OAMethod @responseXml, 'GetChildIntValue', @day OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:publicationMonthsAndDays|*:day'
DECLARE @month int
EXEC sp_OAMethod @responseXml, 'GetChildIntValue', @month OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:publicationMonthsAndDays|*:month'
DECLARE @published nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @published OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:published'
EXEC sp_OAMethod @responseXml, 'GetChildContent', @stationTriplet OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:stationTriplet'
DECLARE @transformErrorsOnly nvarchar(4000)
EXEC sp_OAMethod @responseXml, 'GetChildContent', @transformErrorsOnly OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:transformErrorsOnly'
EXEC sp_OAMethod @responseXml, 'GetChildContent', @unitCd OUT, '*:Body|*:getForecastEquationsResponse|*:return|*:unitCd'
EXEC @hr = sp_OADestroy @xml
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @responseXml
END
GO