Home   Archive   Permalink



Can REBOL access a 'web service'?

The powershell script below seems to run a powershell function that accesses a 'web service' (whatever that is), and then seems to format the data returned from the web service into a 'dot-net object' (whatever that is) so that the 'CurrentWeather' property of that object can be displayed.    
    
Does anyone know if REBOL can do any part of that operation, either access a web service or dissect a dot-net object? I am expecting a negative answer, but it never hurts to ask.
    
Thank you.
    
Powershell script:
    
$City='Minneapolis, Minneapolis-St. Paul International Airport'
$Country='United States'
$webservice = New-WebServiceProxy -Uri 'http://www.webservicex.net/globalweather.asmx?WSDL'
$data = [xml]$webservice.GetWeather($City, $Country)
$data.CurrentWeather

posted by:   Steven White       3-Dec-2015/11:44:08-8:00



This link explains how to get data from that web service:
    
http://www.webservicex.net/globalweather.asmx?op=GetWeather?
    
The easiest way is with GET. You could compose a URL, for example, using 'rejoin:
    
editor http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=New%20York&CountryName=United%20States
    
Read that link into a variable, and you can use 'parse or one of the existing libraries to parse the returned XML data (try Googling "convert xml rebol"):
    
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET"><?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
    <Location>NEW YORK LA GUARDIA AIRPORT , NY, United States (KLGA) 40-47N 73-53W 11M</Location>
    <Time>Dec 03, 2015 - 08:51 PM EST / 2015.12.04 0151 UTC</Time>
    <Wind> from the WNW (300 degrees) at 15 MPH (13 KT):0</Wind>
    <Visibility> 10 mile(s):0</Visibility>
    <SkyConditions> partly cloudy</SkyConditions>
    <Temperature> 46.0 F (7.8 C)</Temperature>
    <DewPoint> 32.0 F (0.0 C)</DewPoint>
    <RelativeHumidity> 57%</RelativeHumidity>
    <Pressure> 30.15 in. Hg (1020 hPa)</Pressure>
    <Status>Success</Status>
</CurrentWeather></string>
    
You can also get the results using POST. Use read/custom in R2 to submit POST data, and to read the returned results, and be sure to use version 2.76 instead of 2.78, because there's some issue with POST in 2.78.
    
You can also use SOAP (that's whats being demonstrated in the Powershell code). There's been some work in REBOL to ease SOAP (you can Google it, and look on rebol.org), but use the other options unless you want to spend more time.

posted by:   Nick       3-Dec-2015/22:10:17-8:00



Here's a POST request formatted by the guidelines given at the link above. This does work in 2.76 (I checked):
    
(The service is at http://www.webservicex.net/globalweather.asmx/GetWeather)
    
service: http://www.webservicex.net/globalweather.asmx/GetWeather
editor read/custom service reduce [
    'POST
    {CityName=New%20York&CountryName=United%20States}
]
    
or you could do it in one line:
    
editor read/custom http://www.webservicex.net/globalweather.asmx/GetWeather reduce ['POST {CityName=New%20York&CountryName=United%20States}]
    
Take a look at http://ross-gill.com/page/XML_and_REBOL and try this:
    
do http://reb4.me/r/altxml
    
editor load-xml read/custom http://www.webservicex.net/globalweather.asmx/GetWeather reduce ['POST {CityName=New%20York&CountryName=United%20States}]
    
Or take a look at http://www.rebol.org/view-script.r?script=xml-parse.r and try this:
    
editor parse-xml+ read/custom http://www.webservicex.net/globalweather.asmx/GetWeather reduce ['POST {CityName=New%20York&CountryName=United%20States}]

posted by:   Nick       3-Dec-2015/22:39:20-8:00



It never crossed my mind, in the past, to save all old versions of REBOL. I happen to have, mainly because of poor housekeeping, versions 2.56 and 2.77, plus the 2.78 I currently use. Is there some place where 2.76 hides on the internet? I did check rebol.com for old versions.
    
Thank you.

posted by:   Steven White       4-Dec-2015/15:41:13-8:00



Off the top of my head, I don't think anything here is version dependent. I'd be surprised if this didn't work in all versions of rebol, as long as you have http protocol and parse.

posted by:   Edoc       4-Dec-2015/16:20:44-8:00



But you need rebol view to use the editor command.
On Core just use print instead.

posted by:   ingo       4-Dec-2015/16:34:25-8:00



There's some undocumented change in 2.78 with POST. See http://rebolforum.com/index.cgi?f=printtopic&permalink=Brother%20Damian6-Nov-2015/3:27:17-8:00&archiveflag=new

posted by:   Nick       4-Dec-2015/19:47:05-8:00



In R2 version 2.77, the way read/custom handles POST data appears to work the same as previous versions, and in fact the service above works fine even with version 2.78. There must be some small change in 2.78 which Carl or someone involved in that upgrade thought would not make a difference in how read/custom handles POST data. I'm going to run some tests to track down exactly what changed - 2.78 definitely does not operate as expected when submitting POST requests to my simple PHP test script.

posted by:   Nick       5-Dec-2015/9:14:36-8:00



It would be good for the general body of REBOL knowledge, but no need to run this down on my account. You have helped me reach my goal, which was to get a basic understanding of the web service concept and use it to solve a particular problem at work.
    
Thank you. Rebolforum is a great resource.

posted by:   Steven White       5-Dec-2015/11:41:24-8:00



@nick, quick question
    
Quoting your GET details posting from above :-
    
This link explains how to get data from that web service:
        
http://www.webservicex.net/globalweather.asmx?op=GetWeather?
        
The easiest way is with GET. You could compose a URL, for example, using 'rejoin:
        
editor http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=New%20York&CountryName=United%20States
        
I have a quick question:- where is the GET word ?    
    
for the POST example,I see you have the word POST

posted by:   yuem       16-Apr-2016/9:07:51-7:00



The question mark in a URL, followed by label1=value1&label2=value2 pairs, forms a
GET request.

posted by:   Nick       16-Apr-2016/17:39:13-7:00



@ Nick.
    
Thanks for the explanation, I will give it a try to get a feel of web service in Rebol.

posted by:   yuem       17-Apr-2016/21:15:39-7:00



if we have to pass certificate details during the web service call, how do we do that ?

posted by:   yuem       24-Apr-2016/21:51:05-7:00



How do you store and retreive the results of a "drop-down" list?
    
Ex: Using a drop-down list instead a field for user input to pull a record from a DB. (VendorNames is populated from another func call).
     label "Date" 60 AFV_Date: field
     label "Vendor" 60 AFV_Vendor: drop-down VendorNames
     label "Qty" 60 AFV_Qty: field

posted by:   Gordon Raboud       15-May-2016/21:42:44-7:00



Oops, sorry, posted in the wrong subject.

posted by:   Gordon Raboud       15-May-2016/21:57:05-7:00



Nevermind, found it.
    
The user selected drop down choice is stored in AFV_Vendor/facets/text and can be assigned to another variable:
    
VendorName: AFV_Vendor/facets/text

posted by:   Gordon Raboud       16-May-2016/8:43:07-7:00



Hi yuem,
It probably is much easier to use CURL using CALL, if your web service requires a client certificate.
Something like:
    
     call/show "" ;fix R2 call bug on Windows
     cmd: {curl -E user:pass@cert.pem http://service/method}
     output: make string! 1024
     error: make string! 1024
     call/output/wait cmd output error
     unless empty? error [print ["ERROR: error"] ]
     parse output rule
     ;...


posted by:   Endo       18-Jun-2016/17:14:19-7:00



Thanks Endo.

posted by:   yuem       17-Jul-2016/11:59:38-7:00