After a few years neglecting RB in back trying to refresh my knowledge of Xojo.
In order to do that I decided to build a webservice that connects to Postgresql and a desktop app communicating with it (IOS is for later).
Thanks to Paul Lefevre’s webinar concerning webservices I managed to get the webservice connection to Postgresql going.
Now I am working on the desktop app, trying to make it connect to the WS. I managed to get it working but part of the code I don’t understand.
I peeked a lot at the files that were made public for the webinar and fore this case I looked at ‘EEiOS’
The following part when copied to my project did NOT work and I am hoping to get an explanation on why this did not want to compile:
I created a new class GeneralWS_Socket with super Xojo.Net.HTTPSocket
I add a Method ‘Hello’
Sub hello()
Self.Send(“POST”, “http://127.0.0.1:8080/special/Hello”)
End Sub
The HandleSpecialURL event on the webservice
Function HandleSpecialURL(Request As WebRequest) As Boolean
Dim data As Text = DefineEncoding(Request.Entity, Encodings.UTF8).ToText
Dim json As JSONItem
Select Case Request.Path
Case “Hello”
json = RespondToHello
Case “GetBasisPrijzen”
json = GetBasisPrijzen
’
'Case “GetCustomer”
'json = GetCustomer(data)
’
'Case “UpdateBasisPrijzen”
'json = UpdateCustomer(data)
Case Else
// Do not process request
Return False
End Select
// Send back data
Request.Print(json.ToString)
Return True
End Function
The respondtoHello method on the Webservice
Function RespondToHello() As JSONItem
Dim jsonResults As New JSONItem
jsonResults.Value(“Hello”) = “Who’s calling ?”
Return jsonResults
End Function
Until here everything worked: I could test the method in Safari and got {“Hello”:“Who’s calling ?”}
Now I subclassed the GeneralWS_Socket in my ConnectWS window and called it WS_Connect
I added a PageReceived Event handler
Sub PageReceived(URL as Text, HTTPStatus as Integer, Content as xojo.Core.MemoryBlock)
Dim jsonData As Text = TextEncoding.UTF8.ConvertDataToText(Content)
Dim json as Dictionary
json = Data.ParseJSON(jsonData)
if json.HasKey(“DBError”) Then
MsgBox(json.Value(“DBError”))
Elseif json.HasKey(“Hello”) Then
Self.lbl_feedback.Text =json.Value(“Hello”)
end if
End Sub
and this I could not get to compile
got 2 errors on this piece of code:
1 The item could not be found: TextEncoding.UTF8
2 The item could not be found: Data
Much cursing and experimenting later I got it working like this
Sub PageReceived(URL as Text, HTTPStatus as Integer, Content as xojo.Core.MemoryBlock)
using Xojo.Core
using Xojo.Data
Dim jsonData As Text = TextEncoding.UTF8.ConvertDataToText(Content)
Dim json as Dictionary
json = Xojo.Data.ParseJSON(jsonData)
if json.HasKey(“DBError”) Then
MsgBox(json.Value(“DBError”))
Elseif json.HasKey(“Hello”) Then
Self.lbl_feedback.Text =json.Value(“Hello”)
end if
End Sub
so I had to explicitly state to use Xojo.Core and Xojo.Data.
I still don’t understand why I need to do this, maybe better said: I still don’t understand why i needed to say this while in EEiOS these statements are nowhere to be found and are not needed to compile.
Anyone cares to get me an AHA-moment ?
TIA