By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

return a paired lists or arraylist from a webservice

P: n/a
I have a webservice that needs to return a paired list, such as created by an
arraylist. The problem appears to be in serlizing the xml. Any help on how
to return a paired list or arraylist would be gratly appreciated.

***********code

<WebMethod()> _
Public Function getMyData() As ArrayList
Dim lvSqlString = "SELECT * FROM PRODUCTS"
Dim myData As New ArrayList

Dim lvSqlCmd As New MySqlCommand
Dim SqlConnection1 As New MySqlConnection
Dim rdr As MySqlDataReader
lvSqlCmd = SqlConnection1.CreateCommand
SqlConnection1.ConnectionString = gvConnectString
lvSqlCmd.CommandText = lvSqlString
SqlConnection1.Open()
rdr = lvSqlCmd.ExecuteReader()
Dim bozo As String = ""
Try
Do While rdr.Read
myData.Add("ProductID")
myData.Add(rdr("ProductID"))
myData.Add("ProductDesc")
myData.Add(rdr("ProductDesc"))
myData.Add("ProductGraphic")
myData.Add(rdr("ProductGraphic"))
Loop
Finally
If Not (rdr Is Nothing) Then
rdr.Close()
rdr = Nothing
End If
If Not (SqlConnection1 Is Nothing) Then
SqlConnection1.Close()
SqlConnection1 = Nothing
End If
End Try

Return myData
End Function

*********** end code
May 11 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Eveready wrote:
I have a webservice that needs to return a paired list, such as
created by an arraylist. The problem appears to be in serlizing the
xml. Any help on how to return a paired list or arraylist would be
gratly appreciated.


You can see a returned ArrayList on a client application as an object
array. This means there isn't really a problem with the XML - it just
comes through as an array of object.

If you put this object array (object[]) into an ArrayList by running
through it with a ForEach loop you will then have an ArrayList at the
client.

(Not as clean as having an ArrayList pass through of course, but this
is one option)
--
Deepak Shenoy
http://shenoyatwork.blogspot.com
May 12 '06 #2

P: n/a
Eveready wrote:
I have a webservice that needs to return a paired list, such as
created by an arraylist. The problem appears to be in serlizing the
xml. Any help on how to return a paired list or arraylist would be
gratly appreciated.


You can see a returned ArrayList on a client application as an object
array. This means there isn't really a problem with the XML - it just
comes through as an array of object.

If you put this object array (object[]) into an ArrayList by running
through it with a ForEach loop you will then have an ArrayList at the
client.

(Not as clean as having an ArrayList pass through of course, but this
is one option)
--
Deepak Shenoy
http://shenoyatwork.blogspot.com
May 12 '06 #3

P: n/a
Deepak, thanks for your reply - but being new to .net, could you provide an
example of what you are talkin about, Please.
thnx

"Deepak Shenoy" wrote:
Eveready wrote:
I have a webservice that needs to return a paired list, such as
created by an arraylist. The problem appears to be in serlizing the
xml. Any help on how to return a paired list or arraylist would be
gratly appreciated.


You can see a returned ArrayList on a client application as an object
array. This means there isn't really a problem with the XML - it just
comes through as an array of object.

If you put this object array (object[]) into an ArrayList by running
through it with a ForEach loop you will then have an ArrayList at the
client.

(Not as clean as having an ArrayList pass through of course, but this
is one option)
--
Deepak Shenoy
http://shenoyatwork.blogspot.com

May 12 '06 #4

P: n/a
Eveready wrote:
Deepak, thanks for your reply - but being new to .net, could you
provide an example of what you are talkin about, Please.
thnx


Eveready,

I used your code (the code you posted, but with fields ProductID,
ProductName and UnitPrice from the NorthWind Products database) in a
web service and wrote a C# client for it. At the client end, I added
the web service as a web reference, and used the following code:

private void button1_Click(object sender, EventArgs e)
{
ArrService.Service serv = new ArrService.Service();

object[] arr = serv.GetMyData();

int arrSize = arr.Length;
// always in threes
int index = 1;
while (index < arrSize)
{
productBindingSource.Add(new Product((int)arr[index],
arr[index + 2].ToString(), arr[index + 4]));
index += 6;
}

dataGridView1.AutoGenerateColumns = false;

}

(My idea was to have the grid show three columns instead of one)

The Product class is defined as:

public class Product
{
private int FProductID;

public int ProductID
{
get { return FProductID; }
set { FProductID = value; }
}
private string FProductName;

public string ProductName
{
get { return FProductName; }
set { FProductName = value; }
}
private double FUnitPrice;

public double UnitPrice
{
get { return FUnitPrice; }
set { FUnitPrice = value; }
}

public Product(int Id, string Name, object Price)
{
ProductID = Id;
ProductName = Name;
if (Price == null)
{
UnitPrice = 0;
}
else
UnitPrice = Double.Parse( Price.ToString() );
}
}

What I've done is: In an array list passed objects of three different
types: Integer, String and Double. THese three are decoded into a
single class named Product and the Grid displays the list of products
(through the BindingSource).

Note that I pass an ArrayList on the server but use an object[] on the
client.

Hope this helps,

--
Deepak Shenoy
http://shenoyatwork.blogspot.com
May 15 '06 #5

P: n/a
Thank You !
Ev

"Deepak Shenoy" wrote:
Eveready wrote:
Deepak, thanks for your reply - but being new to .net, could you
provide an example of what you are talkin about, Please.
thnx


Eveready,

I used your code (the code you posted, but with fields ProductID,
ProductName and UnitPrice from the NorthWind Products database) in a
web service and wrote a C# client for it. At the client end, I added
the web service as a web reference, and used the following code:

private void button1_Click(object sender, EventArgs e)
{
ArrService.Service serv = new ArrService.Service();

object[] arr = serv.GetMyData();

int arrSize = arr.Length;
// always in threes
int index = 1;
while (index < arrSize)
{
productBindingSource.Add(new Product((int)arr[index],
arr[index + 2].ToString(), arr[index + 4]));
index += 6;
}

dataGridView1.AutoGenerateColumns = false;

}

(My idea was to have the grid show three columns instead of one)

The Product class is defined as:

public class Product
{
private int FProductID;

public int ProductID
{
get { return FProductID; }
set { FProductID = value; }
}
private string FProductName;

public string ProductName
{
get { return FProductName; }
set { FProductName = value; }
}
private double FUnitPrice;

public double UnitPrice
{
get { return FUnitPrice; }
set { FUnitPrice = value; }
}

public Product(int Id, string Name, object Price)
{
ProductID = Id;
ProductName = Name;
if (Price == null)
{
UnitPrice = 0;
}
else
UnitPrice = Double.Parse( Price.ToString() );
}
}

What I've done is: In an array list passed objects of three different
types: Integer, String and Double. THese three are decoded into a
single class named Product and the Grid displays the list of products
(through the BindingSource).

Note that I pass an ArrayList on the server but use an object[] on the
client.

Hope this helps,

--
Deepak Shenoy
http://shenoyatwork.blogspot.com

May 15 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.