Categories
Lotus

Lotus web service consumer

I found in internet an example of a web service consumer in lotus environment (Planet Lotus or Wohill) and I wanted to write an other example.
I chose USA Weather web service from WebserviceX.NET.

  1. Create a web service consumer, name it “USA Weather”, set the WSDL file to http://www.webservicex.net/WeatherForecast.asmx?WSDL
    The code in the web service consumer should be: 

    Option Public
    %INCLUDE "lsxsd.lss"
    Class WeatherData_n1 As XSD_ANYTYPE
    	Public Day As XSD_STRING
    	Public WeatherImage As XSD_STRING
    	Public MaxTemperatureF As XSD_STRING
    	Public MinTemperatureF As XSD_STRING
    	Public MaxTemperatureC As XSD_STRING
    	Public MinTemperatureC As XSD_STRING
    	Sub NEW
    	End Sub
    End Class
    Class ArrayOfWeatherData_n1 As XSD_ANYTYPE
    	Public WeatherData() As WeatherData_n1
    	Sub NEW
    	End Sub
    End Class
    Class WeatherForecasts_n1 As XSD_ANYTYPE
    	Public Latitude As Single
    	Public Longitude As Single
    	Public AllocationFactor As Single
    	Public FipsCode As XSD_STRING
    	Public PlaceName As XSD_STRING
    	Public StateCode As XSD_STRING
    	Public Status As XSD_STRING
    	Public Details As ArrayOfWeatherData_n1
    	Sub NEW
    	End Sub
    End Class
    Const n1 = "http://www.webservicex.net"
    Class WeatherForecastSoap_n1 As PortTypeBase
    	Sub NEW
    		Call Service.Initialize ("HttpWwwWebservicexNetWeatherForecast", _
    		"WeatherForecast.WeatherForecastSoap", "http://www.webservicex.net/WeatherForecast.asmx", "WeatherForecastSoap_n1")
    	End Sub
    	Function GetWeatherByZipCode(ZipCode As XSD_STRING) As WeatherForecasts_n1
    		Set GetWeatherByZipCode = Service.Invoke("GetWeatherByZipCode", ZipCode)
    	End Function
    	Function GetWeatherByPlaceName(PlaceName As XSD_STRING) As WeatherForecasts_n1
    		Set GetWeatherByPlaceName = Service.Invoke("GetWeatherByPlaceName", PlaceName)
    	End Function
    End Class
    
  2. Create a lotusscript agent and insert this code: 
    Option Public
    Option Declare
    Use "USA Weather"
    Sub Initialize()
    	Dim serviceClass As New WeatherForecastSoap_n1
    	Dim strRequest As New XSD_STRING
    	Dim session As New NotesSession
    	Dim response As WeatherForecasts_n1
    	Dim details As ArrayOfWeatherData_n1
    	Dim latitude As Single
    	Dim longitude As Single
    	Dim placeName As String
    	Dim stateCode As String
    	Dim calendarDay(5) As String
    	Dim i As Integer
    	Dim minTemperatureC(5) As Integer
    	Dim maxTemperatureC(5) As Integer
    
    	strRequest.Setvaluefromstring("New York")
    
    	Set response = serviceClass.GetWeatherByPlaceName(strRequest)
    
    	latitude = response.Latitude
    	longitude = response.Longitude
    
    	placeName = response.Placename.Getvalueasstring()
    	stateCode = response.Statecode.Getvalueasstring()
    
    	Print placeName & " " & stateCode & " lon.:" & longitude & " lat.:" & latitude
    
    	Set details = response.Details
    
    	For i = 0 To 5
    		calendarDay(i) = details.Weatherdata(i).Day.Getvalueasstring()
    		minTemperatureC(i) = CInt(details.Weatherdata(i).minTemperatureC.Getvalueasstring())
    		maxTemperatureC(i) = CInt(details.Weatherdata(i).maxTemperatureC.Getvalueasstring())
    
    		Print calendarDay(i) & " T min:" & minTemperatureC(i) & " T max:" & maxTemperatureC(i)
    	Next
    
    End Sub
    
  3. Run the agent and look the status bar

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.