Retrieve a dataset from web service and loop through it

sacad

Member
Licensed User
Can someone please help me to connect to a dataset that i have written in a web service? ive tested this on windows on a server and it works fine. Here is my web service vb code that connects to a server.

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService1
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function getdataset() As DataSet
' Dim teststr As String
'Dim myconnection As New SqlConnection("add name=OrgStructureConnectionString connectionString=Data Source=infpe006;Initial Catalog=OrgStructure;User ID=Cornenew;Password=corne providerName=System.Data.SqlClient")

Dim myconnection As New SqlConnection("Data Source=infpe006;Initial Catalog=OrgStructure;User ID=Cornenew;Password=corne;")
Dim mycommand As String = ("Select * from OrganizationStructure")

Dim da As New SqlDataAdapter(mycommand, myconnection)

Dim ds As New DataSet

'ds.Tables.Add(dt)
da.Fill(ds, "OrganizationStructure")

da.Fill(ds, "OrganizationStructure")




Return ds
End Function
End Class

what i want to do in android is this:
Dim s As New ServiceReference1.WebService1SoapClient
Dim str As String

Dim ds As New DataSet
ds = s.getdataset()

Dim dt As New DataTable
dt = ds.Tables("OrganizationStructure")

For Each row In dt.Rows
Dim Child As String = row.Item(1).ToString
str &= Child & vbCrLf
Next

MsgBox(str)
End Sub

What this do is getting the dataset from the web service and then i place the dataset in a datatable so i can loop through it. I have no idea how i can do this in android? im very new to this and apologize if there is already an example on b4a but couldnt find anyone with sample code.
 

sacad

Member
Licensed User
Thanx Erel i did see that example so you did you web service on a page and not in a web service so dont know if my web service will work in android if i create a dataset function that will call a dataset?

Here is your code and i just want to be clear and comment in it where im unsure if thats ok?
B4X:
Sub Process_Globals
    Dim ServerUrl As String
"SO THIS IS WHERE ILL PUT MY WEB SERVICE ADDRESS AND IF ITS LOCALHOST SHOULD I THEN JUST PUT MY IP IN THE PLACE OF LOCALHOST?
    ServerUrl = "http://www.example.com/test1.aspx"
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
"NOT SURE WHAT THIS IS AND DO AND IS JOB DONE A BUILD IN FUNCTION?
        HttpUtils.CallbackActivity = "Main"
        HttpUtils.CallbackJobDoneSub = "JobDone"
    End If
        "SO HERE I MUST SAY ("JOB1" WHICH IS A BUILD IN FUNCTION I GUESS,SERVERURL AND THEN " " BECAUSE I DONT HAVE ANY PARAMETERS OR STRING VALUES THAT IS SEND TO MY SERVCE?????????????? 
    HttpUtils.PostString("Job1", ServerUrl, "SELECT col1, col2 FROM Table_1")
End Sub

Sub Activity_Resume
"WHY DO YOU USE THIS?
    If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
End Sub

Sub JobDone (Job As String)
    If HttpUtils.IsSuccess(ServerUrl) Then
SO HERE I MUST DECLARE A DATASET AND NOT A STRING VALUE?
        Dim parser As JSONParser
        Dim response As String
        response = HttpUtils.GetString(ServerUrl)
        parser.Initialize(response)
"hOW WILL YOU LOOP THROUGH A DATASET SINCE IN VB YOU HAVE TO USE A DATA TABLE???????
        Dim rows As List
        rows = parser.NextArray
        
        'work with result
        'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
        For i = 0 To rows.Size - 1
            Log("Rows #" & i)
            Dim m As Map
            m = rows.Get(i)
            Log("col1=" & m.Get("col1")) 'log the values of col1 and col2
            Log("col2=" & m.Get("col2"))
        Next
    End If
"THIS CLOSE IT?"
    HttpUtils.Complete = False
End Sub
Erel dont you maybe have an example that shows how to access a dataset information that is retrieved from a web service or will i have to do it like this? if im correct i can use the dbutils to get a dataset but based on my comments in your code i dont know i can do it that way.
What will be the best way you think i must do to retrieve information from a dataset and how?
Thank you for helping me. You really amazing and i learn a lot from you.:D
 
Upvote 0

sacad

Member
Licensed User
Please use [ code ] tags when posting code.

You should read the HttpUtils tutorial to better understand the code.
Ok will go through it. So just to make sure:
1. So i will be able to retrieve a dataset as web service in a http or can it only be string values?
2.If i want to host a local web service i must download wamp and go through tutorials to set up for sql server
3.do u maybe have any samples on dataset retrieval you willing to share or know of someone that can help?

The sql tutorial on connection to sql is really awesome and sorry if my posts is sometime not the standard you want but that how we learn.
Will go through the httputils as soon as exams are over and i think also the DButils for datasets
 
Last edited:
Upvote 0

Theo_van_Putten

New Member
Licensed User
Can someone please help me to connect to a dataset that i have written in a web service? ive tested this on windows on a server and it works fine. Here is my web service vb code that connects to a server.

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService1
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function getdataset() As DataSet
' Dim teststr As String
'Dim myconnection As New SqlConnection("add name=OrgStructureConnectionString connectionString=Data Source=infpe006;Initial Catalog=OrgStructure;User ID=Cornenew;Password=corne providerName=System.Data.SqlClient")

Dim myconnection As New SqlConnection("Data Source=infpe006;Initial Catalog=OrgStructure;User ID=Cornenew;Password=corne;")
Dim mycommand As String = ("Select * from OrganizationStructure")

Dim da As New SqlDataAdapter(mycommand, myconnection)

Dim ds As New DataSet

'ds.Tables.Add(dt)
da.Fill(ds, "OrganizationStructure")

da.Fill(ds, "OrganizationStructure")




Return ds
End Function
End Class

what i want to do in android is this:
Dim s As New ServiceReference1.WebService1SoapClient
Dim str As String

Dim ds As New DataSet
ds = s.getdataset()

Dim dt As New DataTable
dt = ds.Tables("OrganizationStructure")

For Each row In dt.Rows
Dim Child As String = row.Item(1).ToString
str &= Child & vbCrLf
Next

MsgBox(str)
End Sub

What this do is getting the dataset from the web service and then i place the dataset in a datatable so i can loop through it. I have no idea how i can do this in android? im very new to this and apologize if there is already an example on b4a but couldnt find anyone with sample code.


Did you have any succes with your problem ?

I have a similar issue. The applications that I work with consist of many webservices. I have no problem in calling them.
But I fail to proces the returning results (tha datasets).

I would be very pleased if you can send me some code to process the return dataset.
 
Upvote 0
Top