473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

return a paired lists or arraylist from a webservice

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
5 1384
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Nofelt | last post by:
Hey all, I want to return an xml structure without .net trying to inject any of its xml schema? Can this be done? Here is the scenario: I'm running into an issue with the return string of my...
4
by: jean.ockert | last post by:
Greetings. Access version 2003 on an XP system I am using the template "Event Management" database as the primary database and need additional functionality added. I have a dance studio. ...
9
by: Ryan Taylor | last post by:
Hello. I am trying to overload a method so that I have four possible working copies. The only difference between the four methods is what to search by and in what manner to return the results....
7
by: Shaine Fisher | last post by:
I have had a look around but I'm either not finding or not seeing the answer to this, what i want to do is reurn the results as an array, or some other worldly useful format that flash mx2004 can...
5
by: Pete Hearn | last post by:
Hello All, New to the whole C#/Webservice/ADO.NET thing, so apologies in advance if this is a daft question! I have a webservice which returns a dataset - no problem there and all very...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
6
by: Whoever | last post by:
Here's what I have A custom collection: public class aUser { public string UserName { get {...} set {...} } public class UserList : System.Collection.CollectionBase { public void Add(aUser...
1
by: Ankita | last post by:
Hi I have a webservice which has 2 webmethods: 1.One that returns a String 2.One that returns an ArrayLis I need to use this WebService in VBA environment. I am using the Webservices References...
4
by: Military Smurf | last post by:
I'm interested in writing a web service that will return more than one value. What's the best way to accomplish this? I was wondering if an array would be best, but I'd like to know if there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.