You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Current »

Some examples on how to connect to the FEWS PI-XML SOAP Web Service. To connect to the PI-XML SOAP Web Service a SOAP Request has to be constructed. See FEWS PI SOAP Web Service Request examples for some sample requests.

Python

To get time series from FEWS using Python the following example uses the requests module and reads the time series PI-XML content from the SOAP response.

# Simple example that uses python to get timeSeries from the Delft-FEWS PI Soap Service.
import requests
import xml.etree.ElementTree as ET

soapMessage = """<?xml version="1.0" ?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:few="http://fewspiservice.wldelft.nl">
   <soapenv:Header/>
   <soapenv:Body>
      <few:getTimeSeries>
         <few:queryParams>
            <endTime>2010-01-01T00:00:00Z</endTime>
            <locationIds>63306260000</locationIds>
            <parameterIds>T.obs.mean</parameterIds>
            <startTime>2000-01-01T00:00:00Z</startTime>
         </few:queryParams>
      </few:getTimeSeries>
   </soapenv:Body>
</soapenv:Envelope>"""

url = 'http://localhost:8080/FewsWebServices/fewspiservice'
headers = {
    "Content-Type": "text/xml",
    "SOAPAction" : "\"\""
}

response = requests.post(url=url, data=soapMessage, headers=headers)
data = response.text
xmlTree = ET.fromstring(data)
piXmlResponse = None
for elem in xmlTree.iter():
    if elem.tag == 'return':
        piXmlResponse = elem.text
        
if piXmlResponse is not None:
    print(piXmlResponse)
    # For further processing, the PI-XML response can be parsed as well.
    parsedPiXml = ET.fromstring(piXmlResponse)
else:
    print('No pi xml response found')

  • No labels