473,659 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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. ConnectionStrin g = gvConnectString
lvSqlCmd.Comman dText = lvSqlString
SqlConnection1. Open()
rdr = lvSqlCmd.Execut eReader()
Dim bozo As String = ""
Try
Do While rdr.Read
myData.Add("Pro ductID")
myData.Add(rdr( "ProductID" ))
myData.Add("Pro ductDesc")
myData.Add(rdr( "ProductDes c"))
myData.Add("Pro ductGraphic")
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 1401
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(o bject sender, EventArgs e)
{
ArrService.Serv ice serv = new ArrService.Serv ice();

object[] arr = serv.GetMyData( );

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

dataGridView1.A utoGenerateColu mns = 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(o bject sender, EventArgs e)
{
ArrService.Serv ice serv = new ArrService.Serv ice();

object[] arr = serv.GetMyData( );

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

dataGridView1.A utoGenerateColu mns = 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
1385
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 .NET webservice. I am attempting to return an xml string similar to this: <?xml version="1.0" encoding="utf-8" ?>
4
1865
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. Dance "events" do not change, only the months they occur. I have Attendee, EventTypes, Registration, and Classes tables. I need to add the following... To be able to track who is registering for particular dance classes
9
20585
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. So I have the following. public static ArrayList GetRoles(int userID) public static ArrayList GetRoles(string username) public static string GetRoles(int userID) // Error 1 public static string GetRoles(string username) // Error 2
7
5762
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 read. But when I did thiss I was told datasets were the way to go, but needs an array, prefer typed as were changing it. Here is the current code: (shortened for readability) public class WebService1{
5
10950
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 standard. However, I want to pass an arraylist of objects to the method which returns the dataset (the arraylist contains QBE parameter objects) but the compiler chokes saying it wants an object array instead.
12
4120
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
1855
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 user) {...} public aUser this {...}
1
3201
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 Tool 2.0 for accessing this Webservice. I've added the WebService and I'm able to get the string returned from the first web method. But I'm getting error when trying to access the webmethod which returns an arraylist I found this Microsoft Web...
4
1956
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 better way.
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.