Skip to content

Instantly share code, notes, and snippets.

@magnuspalmer
Created August 22, 2016 17:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnuspalmer/c22f85d1a1653308f3576dc3ea2bd4ca to your computer and use it in GitHub Desktop.
Save magnuspalmer/c22f85d1a1653308f3576dc3ea2bd4ca to your computer and use it in GitHub Desktop.
Simple Groovy SOAP request using wslite
@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.0')
import wslite.soap.*
import groovy.xml.*
def client = new SOAPClient('http://www.webservicex.net/globalweather.asmx')
String city = 'Stockholm'
String country = 'Sweden'
def weatherResponse = client.send(){
version SOAPVersion.V1_2 // SOAPVersion.V1_1 is default
soapNamespacePrefix "soap12" // "soap-env" is default
envelopeAttributes "xmlns:ns1":"http://www.webserviceX.NET"
header {}
body {
'ns1:GetWeather' {
'ns1:CityName'(city)
'ns1:CountryName'(country)
}
}
}
println weatherResponse.body
<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
<Location>Stockholm / Bromma, Sweden (ESSB) 59-21N 017-57E 14M</Location>
<Time>Aug 22, 2016 - 01:20 PM EDT / 2016.08.22 1720 UTC</Time>
<Wind> from the S (180 degrees) at 10 MPH (9 KT):0</Wind>
<Visibility> greater than 7 mile(s):0</Visibility>
<Temperature> 68 F (20 C)</Temperature>
<DewPoint> 53 F (12 C)</DewPoint>
<RelativeHumidity> 59%</RelativeHumidity>
<Pressure> 30.06 in. Hg (1018 hPa)</Pressure>
<Status>Success</Status>
</CurrentWeather>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment