Android Question Sending HTTP Get Request to Web service with SQL Statement

GeoffT660

Active Member
Licensed User
I have a web service that allows the program to call a function with a URL Encoded Sql statement that will return the results in xml format. So far I have been unable to accomplish this using HTTPUtils2 I then need to parse the xml into a table that I've already created. The get statement I would issue is http://MyServer/Service/Service1.asmx?op=GetSQL&strSQL=SELECT UNO, BRKRNO, EFL FROM EmpTbl Where UNO = 'itx2'" (The select statement would need to be URL Encoded) and the results I get which also matches the table structure. Please help as I'm fairly new to B4a

<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="My Server/Serice"><NewDataSet> <Table> <UNO>itx2</UNO> <BRKRNO>BOISE</BRKRNO> <EFL>Loise TX 2</EFL> </Table> </NewDataSet></string>
 

sorex

Expert
Licensed User
that's not the point, you should send over less data and not a full query.

it just takes a sniffer and some knowledge to read out your entire database schema the way you did it now.
 

GeoffT660

Active Member
Licensed User
I did change the names to protect the innocent
What Type of object do I save the results to?
that's not the point, you should send over less data and not a full query.

it just takes a sniffer and some knowledge to read out your entire database schema the way you did it now.
it ain't smart to send full queries over the net.

just send the search over as

http://MyServer/Service/Service1.asmx?op=GetSQL_UNOSEARCH&id=itx2

and get the right query based on the op value and feed it with the id value as search parameter
Am I still using httpUtils2? What object or how will I read the results?
 

sorex

Expert
Licensed User
you need to use httputils to get the data.

in the download completed event you can store the response text in a variable and parse it with a json or xml parser.

Erel has made complete examples of both and they are here on the forum.
 

GeoffT660

Active Member
Licensed User
JobDone event
I've tried a bunch of different code based on the HttpUtil2 examples and I still can't get it. Can you give me a code example based on my scenario of sending a SQL Statement, with or without the "Where" parameter. Please.
 

GeoffT660

Active Member
Licensed User
I know about these, I've been working with them all day trying to adapt their examples to fit where I can send SQL Select Statement to Web Service Process. I don't think I'm understanding the array portion or how to call the procedure on my Web Service with the required SQL statement as the parameter
...Service1.asmx?op=GetSQL&strSQL=" & strSQL
 

sorex

Expert
Licensed User
I think it's best to setup the server part first and use dummy data in the table.

then zip up your project and attach it here so that we can see what you have, what goes wrong and how we can help you out.
 

GeoffT660

Active Member
Licensed User
This is getting bit more complicated than I was hoping. Is there a way to issue a simple HTTP Statement and then read the results as I can do in a browser? If I try to do this with the httpjob object it as in:
job1.GetString("http://MyServer/Service1.asmx?op=GetSQL&strSQL="& strSql) I get an error in code that says "Array expected" in all except GetString2 but that doesn't work either
 

sorex

Expert
Licensed User
or atleast post some code so that we can have a look at what you are doing wrong
 

GeoffT660

Active Member
Licensed User
or atleast post some code so that we can have a look at what you are doing wrong
I'm using this code
strGet = "http://" & gp_IPaddr & "/Service1.asmx/GetSQL?&strSQL=" & su.EncodeUrl(strSql,"UTF8")
job1.GetString2(strGet)
strGet = http://MyServer/Service1.asmx/GetSQL?&strSQL=strSQLSelectStatement

If I post the strGet statement copied in the log to the browser address then I get the data expected in the browser but when I run this in B4a I get: "java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)"

In another RAD environment for PPC and Palm I just issue strResult = HTTP_GET(strGet, strResponseLength)
Not sure but maybe HTTPUtils2 won't work with my current web services the way they are.
Thanks for your help.
 

Erel

Administrator
Staff member
Licensed User
Your code is wrong. HttpUtil2 manages the request and raises the JobDone event when the response is available. As I wrote above you should go over HttpUtils2 tutorial. It is not complicated to use it.

In another RAD environment for PPC and Palm I just issue strResult = HTTP_GET(strGet, strResponseLength)
Waiting for the response while blocking the main thread leads to unresponsive applications. Android doesn't allow you to block the main thread.
 

GeoffT660

Active Member
Licensed User
Your code is wrong. HttpUtil2 manages the request and raises the JobDone event when the response is available. As I wrote above you should go over HttpUtils2 tutorial. It is not complicated to use it.


Waiting for the response while blocking the main thread leads to unresponsive applications. Android doesn't allow you to block the main thread.
I'm still unable to get this to work even using the simplest b4A example listed below. I've tried calling this in a separate activity "GetData" and attempted to use CallSubDelayed but it never calls the JobDone event. Please let me know what I'm doing wrong. my Log shows this:

Activity (main) Pause, UserClosed = false **
** Activity (getdata) Create, isFirst = true **
sending message to waiting queue of uninitialized activity (submitjob)
** Activity (getdata) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Activity (getdata) Pause, UserClosed = true **
** Activity (main) Resume **

Sub Activity_Create(FirstTime AsBoolean)

Dim b4a As String
b4a = "http://www.basic4ppc.com"
Dim job1 As HttpJob
job1.Initialize("Job1", Me)
job1.Download(b4a)

End Sub

Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Dim s As String
s=Job.GetString
Log(s)
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
 

GeoffT660

Active Member
Licensed User
I'm still unable to get this to work even using the simplest b4A example listed below. I've tried calling this in a separate activity "GetData" and attempted to use CallSubDelayed but it never calls the JobDone event. Please let me know what I'm doing wrong. my Log shows this:

Activity (main) Pause, UserClosed = false **
** Activity (getdata) Create, isFirst = true **
sending message to waiting queue of uninitialized activity (submitjob)
** Activity (getdata) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Activity (getdata) Pause, UserClosed = true **
** Activity (main) Resume **

Sub Activity_Create(FirstTime AsBoolean)

Dim b4a As String
b4a = "http://www.basic4ppc.com"
Dim job1 As HttpJob
job1.Initialize("Job1", Me)
job1.Download(b4a)

End Sub

Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Dim s As String
s=Job.GetString
Log(s)
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Nevermind. I think I found the issue was that I was trying to step through my code with the debugger and it wouldn't call the JobDone Event. If I let it run through then it works
 
Top