473,404 Members | 2,170 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,404 software developers and data experts.

Return Custom Collection and Web Services

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[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("UserList", typeof(UserList))]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

On the client side, when adding a reference to the webservice, it can only
see aUser object, but not UserList object. So I have to do

localhost.PhoneSvc svc = new WebApplication1.localhost.PhoneSvc();
localhost.aUser[] a = svc.getContact("test");

Is there a way to expose the collection object, so that you can do something
like this?

UserList ul = svc.getUserList("tester");

I know there are several articles out there that create wrapper class so
that it can be bounded to datagrid, etc. But none of them seems to be able
to expose the collection object directly.

Any ideas? Thanks.
Nov 18 '05 #1
6 1847
Try this:

[WebMethod]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Whoever" <bz****@hotmail.com> wrote in message
news:es*************@TK2MSFTNGP11.phx.gbl...
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[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("UserList", typeof(UserList))]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

On the client side, when adding a reference to the webservice, it can only
see aUser object, but not UserList object. So I have to do

localhost.PhoneSvc svc = new WebApplication1.localhost.PhoneSvc();
localhost.aUser[] a = svc.getContact("test");

Is there a way to expose the collection object, so that you can do something like this?

UserList ul = svc.getUserList("tester");

I know there are several articles out there that create wrapper class so
that it can be bounded to datagrid, etc. But none of them seems to be able to expose the collection object directly.

Any ideas? Thanks.

Nov 18 '05 #2
We've used an array as the return type for our web services, and that worked
ok. You can always implement an AddRange(User[] users) method in your
collection to re-create the collection from the array ...

Angel
O:]
"Whoever" <bz****@hotmail.com> wrote in message
news:es*************@TK2MSFTNGP11.phx.gbl...
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[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("UserList", typeof(UserList))]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

On the client side, when adding a reference to the webservice, it can only
see aUser object, but not UserList object. So I have to do

localhost.PhoneSvc svc = new WebApplication1.localhost.PhoneSvc();
localhost.aUser[] a = svc.getContact("test");

Is there a way to expose the collection object, so that you can do something like this?

UserList ul = svc.getUserList("tester");

I know there are several articles out there that create wrapper class so
that it can be bounded to datagrid, etc. But none of them seems to be able to expose the collection object directly.

Any ideas? Thanks.

Nov 18 '05 #3
Thanks for the help. You mean without the [return: XmlEelement...]? I
tried that but it's the same.

It seems whenever you return a class that inherits
System.Collections.CollectionBase, directly or indirectly, it ends up as an
array of the object it contains, never the collection object itself.

Am I missing something?

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:O9**************@tk2msftngp13.phx.gbl...
Try this:

[WebMethod]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Whoever" <bz****@hotmail.com> wrote in message
news:es*************@TK2MSFTNGP11.phx.gbl...
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[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("UserList", typeof(UserList))]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

On the client side, when adding a reference to the webservice, it can only see aUser object, but not UserList object. So I have to do

localhost.PhoneSvc svc = new WebApplication1.localhost.PhoneSvc();
localhost.aUser[] a = svc.getContact("test");

Is there a way to expose the collection object, so that you can do

something
like this?

UserList ul = svc.getUserList("tester");

I know there are several articles out there that create wrapper class so
that it can be bounded to datagrid, etc. But none of them seems to be

able
to expose the collection object directly.

Any ideas? Thanks.


Nov 18 '05 #4
For a more complicated case, such as:

<Department name='something'>
<Group id='123'>
<User>...</User>
<User>...</User>
</Group>
<Group>
...
</Group>
</Department>
<Department>
...
</Department>

Array is not as convenient. Also, it's also much better if you can:

DepartmentList deptlist = svc.getDepartment()
foreach (Department d in deptlist)
GroupList grplist = svc.getGroup(d);

(this last code is not real and may totally be wrong, since I haven't figure
out how to expose the list in the first place)
"Angelos Karantzalis" <ak**********@yahoo.com> wrote in message
news:O6**************@TK2MSFTNGP09.phx.gbl...
We've used an array as the return type for our web services, and that worked ok. You can always implement an AddRange(User[] users) method in your
collection to re-create the collection from the array ...

Angel
O:]
"Whoever" <bz****@hotmail.com> wrote in message
news:es*************@TK2MSFTNGP11.phx.gbl...
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[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("UserList", typeof(UserList))]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

On the client side, when adding a reference to the webservice, it can only see aUser object, but not UserList object. So I have to do

localhost.PhoneSvc svc = new WebApplication1.localhost.PhoneSvc();
localhost.aUser[] a = svc.getContact("test");

Is there a way to expose the collection object, so that you can do

something
like this?

UserList ul = svc.getUserList("tester");

I know there are several articles out there that create wrapper class so
that it can be bounded to datagrid, etc. But none of them seems to be

able
to expose the collection object directly.

Any ideas? Thanks.


Nov 18 '05 #5
Hi all (specially Whoever),

I've got your same problem. My WebMethod must return an ArrayList of custom
objects. Nevertheless, when calling the web method from my ASP.NET page, it
returns me an array of objetcs. What can I do? I've been trying to
deserialize objects with XMLInclude and so on, but I haven't got very clear
ideas about these issues of serialization adn deserialization.

I want the client to recognize my custom objects inside the Arraylist
because I must bound the returned ArrayList to a DataGrid and this way it's
no posible. First of all, do Web Services work well with Arraylists?

"Whoever", where are these articles telling about making wrappers in order
to bound DataGrids?

I'm willing your beautiful ideas. Thanks in advance.
"Whoever" wrote:
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[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("UserList", typeof(UserList))]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

On the client side, when adding a reference to the webservice, it can only
see aUser object, but not UserList object. So I have to do

localhost.PhoneSvc svc = new WebApplication1.localhost.PhoneSvc();
localhost.aUser[] a = svc.getContact("test");

Is there a way to expose the collection object, so that you can do something
like this?

UserList ul = svc.getUserList("tester");

I know there are several articles out there that create wrapper class so
that it can be bounded to datagrid, etc. But none of them seems to be able
to expose the collection object directly.

Any ideas? Thanks.

Nov 18 '05 #6
http://www.ftponline.com/vsm/2003_06...olumns/aspnet/

Datagrid will bound to Properties not field. You can fix that. But I would
really like to see the list object pass to the client so that you can
declare

UserList ul;

Instead of

aUser[] users;

from the client side. Especially with multile level xml document.

Maybe it's not doable with custom collection?
"MIGUEL" <MI****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
Hi all (specially Whoever),

I've got your same problem. My WebMethod must return an ArrayList of custom objects. Nevertheless, when calling the web method from my ASP.NET page, it returns me an array of objetcs. What can I do? I've been trying to
deserialize objects with XMLInclude and so on, but I haven't got very clear ideas about these issues of serialization adn deserialization.

I want the client to recognize my custom objects inside the Arraylist
because I must bound the returned ArrayList to a DataGrid and this way it's no posible. First of all, do Web Services work well with Arraylists?

"Whoever", where are these articles telling about making wrappers in order
to bound DataGrids?

I'm willing your beautiful ideas. Thanks in advance.
"Whoever" wrote:
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[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("UserList", typeof(UserList))]
public UserList getUserList(string search) {
UserList ul = new UserList();
return ul;
}

On the client side, when adding a reference to the webservice, it can only see aUser object, but not UserList object. So I have to do

localhost.PhoneSvc svc = new WebApplication1.localhost.PhoneSvc();
localhost.aUser[] a = svc.getContact("test");

Is there a way to expose the collection object, so that you can do something like this?

UserList ul = svc.getUserList("tester");

I know there are several articles out there that create wrapper class so
that it can be bounded to datagrid, etc. But none of them seems to be able to expose the collection object directly.

Any ideas? Thanks.

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt | last post by:
Hello all, The app we are working on uses custom errors extensively to provide friendly error pages to users whilst logging the actual exceptions behind the scenes. However.... We are now...
5
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called...
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...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
1
by: Thomas D. | last post by:
Hello all, I'm using the IXmlSerializable interface for a project and encounter some problems when testing my webservice in a client application. I know this interface is undocumented and not...
2
by: gbanister | last post by:
I'd like to repost a message that I found in this group almost one year ago, because it's the exact problem I'm in and there was no solution offered to this post last year. (note: I was not the...
2
by: Ghanashyam | last post by:
I have a custom collection (Dervided from CollectionBase) and it works pretty well when I consume it from C# console app.But it is not working if I return the collection from a web service.The IE...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
1
by: =?Utf-8?B?Qi5BaGxzdGVkdA==?= | last post by:
Hi all, This is something that I have been toying with for about a week now. What I want to achieve is Install a Service with Customised parameters (using InstallUtil.exe) for User Name. Example...
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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,...
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...

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.