Hello. I’ve been practicing with web services, and I almost have enough to start implementing it. I watched Paul’s tutorials on this and saw there were links for the example projects for 1) the web service, and 2) the client (EE iOS), but these were from 2015, so I couldn’t follow along completely. Then I found Javier’s blog post, which was more relevant for me (Web Services Part II: Xojo Web, at your service – Xojo Programming Blog)
This blog post shows how to return all of the data to a listbox and how to update a record. So far, I’ve gotten the ShowAll, Add, Update, and Delete. What I am needing help with is the web service returning the data for one specific record.
I found an updated example project in Communication > Internet > Web Services > EddiesWebService, which is obviously for the web service. If there is a project in the examples that is a companion to this project as the client, I think that would help me out because the web service example includes a function to GetCustomer (a single record), but I don’t know how it is called from the client side
I did get the process to work for the purposes, but I know it is not the most streamlined way of doing it. On the client, I am following Javier’s post to find a record, similar to how an Update or Delete would work
dim d As New Dictionary
d.Value("RegCodes") = txtCode.Text
dim item As New JSONItem
item.Value("newCode") = d
CodesSocket11.sendItem(item,"http://127.0.0.1:8080/FindCode")
Then on the web service side, the FindCode method looks like this
dim title As String = item.Value("RegCodes")
Dim sql As String = "SELECT * FROM registerCodesTEST WHERE RegCodes = ?"
Dim rs As RowSet = mDbRegister.SelectSQL(sql, title)
if rs.RowCount > 0 then
theSearchedCode = rs.Column("RegCodes").StringValue
CodeFound = True
else
CodeFound = False
end if
In the HandleURL, I have it like this
Case "FindCode"
dim data As String = Request.Body.DefineEncoding(encodings.UTF8)
dim Input As JSONItem = New JSONItem(data)
FindCode(Input.Value("newCode"))
if CodeFound = true then
dim output As JSONItem = DisplayCode
Response.Header("charset") = "utf-8"
Response.MIMEType = "application/json"
Response.Status = 200
response.write( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
end if
I know this is not the best practice, but it was the only way I could figure out how to first find the record based on user input and if found, then return the result back to the client. I feel like on the client side, I should be able to send the request to the web service with the input data and then have that returned back to the client. Any suggestions? This is a new area for me