Description Usage Arguments Value Examples
View source: R/MakeSOAPEnvelope.R
A helper function that makes a SOAP envelope to send to the CUAHSI WaterOneFlow SOAP web service. It is internally used by the GetSites, GetSiteInfo, GetVariables and GetValues functions.
1 | MakeSOAPEnvelope(CUAHSINamespace, MethodName, parameters = NULL)
|
CUAHSINamespace |
The SOAP namespace. This must be either "http://www.cuahsi.org/his/1.0/ws" for WaterML 1.0, or "http://www.cuahsi.org/his/1.1/ws" for WaterML 1.1 |
MethodName |
The name of the WaterOneFlow web service method. It can be one of the following values: "GetSites", "GetSitesObject", "GetSitesByBoxObject", "GetSiteInfoObject", "GetVariablesObject", "GetValuesObject" |
parameters |
An optional vector of named parameters for the web method. For GetSites, GetSitesObject and GetVariables no parameters are required. For GetSiteInfoObject you need the "site" parameter. For GetValuesObject you need the "location", "variable", "startDate" and "endDate" parameters. |
A <soap:Envelope> text in XML format. This text is send in a HTTP POST body to the SOAP service. Two headers must be sent in the request: Content-Type="text/XML" and SOAPAction=paste(CUAHSINamespace, MethodName). For example if MethodName is GetSites and the WaterML version is 1.1, then SOAPAction="http://www.cuahsi.org/his/1.1/ws/GetSites".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | library(httr)
library(XML)
myEnvelope <- MakeSOAPEnvelope("http://www.cuahsi.org/his/1.1/ws/", "GetSitesObject")
SOAPAction <- "http://www.cuahsi.org/his/1.1/ws/GetSitesObject"
url <- "http://hydrodata.info/chmi-d/cuahsi_1_1.asmx"
downloaded <- FALSE
err <- tryCatch({
response <- POST(url, body = myEnvelope,
add_headers("Content-Type" = "text/xml", "SOAPAction" = SOAPAction))
downloaded <- TRUE
},error = function(e) {
print(conditionMessage(e))
})
if (downloaded) {
status.code <- http_status(response)$category
WaterML <- xmlParse(response)
WaterML
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.