473,835 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti on.CollectionBa se {
public void Add(aUser user) {...}
public aUser this[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("Use rList", typeof(UserList ))]
public UserList getUserList(str ing 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.Phone Svc svc = new WebApplication1 .localhost.Phon eSvc();
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 1860
Try this:

[WebMethod]
public UserList getUserList(str ing 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******** *****@TK2MSFTNG P11.phx.gbl...
Here's what I have

A custom collection:
public class aUser {
public string UserName { get {...} set {...}
}

public class UserList : System.Collecti on.CollectionBa se {
public void Add(aUser user) {...}
public aUser this[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("Use rList", typeof(UserList ))]
public UserList getUserList(str ing 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.Phone Svc svc = new WebApplication1 .localhost.Phon eSvc();
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******** *****@TK2MSFTNG P11.phx.gbl...
Here's what I have

A custom collection:
public class aUser {
public string UserName { get {...} set {...}
}

public class UserList : System.Collecti on.CollectionBa se {
public void Add(aUser user) {...}
public aUser this[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("Use rList", typeof(UserList ))]
public UserList getUserList(str ing 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.Phone Svc svc = new WebApplication1 .localhost.Phon eSvc();
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.Collecti ons.CollectionB ase, 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******@takem pis.com> wrote in message
news:O9******** ******@tk2msftn gp13.phx.gbl...
Try this:

[WebMethod]
public UserList getUserList(str ing 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******** *****@TK2MSFTNG P11.phx.gbl...
Here's what I have

A custom collection:
public class aUser {
public string UserName { get {...} set {...}
}

public class UserList : System.Collecti on.CollectionBa se {
public void Add(aUser user) {...}
public aUser this[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("Use rList", typeof(UserList ))]
public UserList getUserList(str ing 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.Phone Svc svc = new WebApplication1 .localhost.Phon eSvc();
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.getDepartme nt()
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**********@y ahoo.com> wrote in message
news:O6******** ******@TK2MSFTN GP09.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******** *****@TK2MSFTNG P11.phx.gbl...
Here's what I have

A custom collection:
public class aUser {
public string UserName { get {...} set {...}
}

public class UserList : System.Collecti on.CollectionBa se {
public void Add(aUser user) {...}
public aUser this[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("Use rList", typeof(UserList ))]
public UserList getUserList(str ing 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.Phone Svc svc = new WebApplication1 .localhost.Phon eSvc();
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.Collecti on.CollectionBa se {
public void Add(aUser user) {...}
public aUser this[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("Use rList", typeof(UserList ))]
public UserList getUserList(str ing 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.Phone Svc svc = new WebApplication1 .localhost.Phon eSvc();
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****@discuss ions.microsoft. com> wrote in message
news:F7******** *************** ***********@mic rosoft.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.Collecti on.CollectionBa se {
public void Add(aUser user) {...}
public aUser this[int Index] {...}
}

A web service:

[WebMethod]
[return: XmlElement("Use rList", typeof(UserList ))]
public UserList getUserList(str ing 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.Phone Svc svc = new WebApplication1 .localhost.Phon eSvc();
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
2549
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 having to integrate some Web services into the application using the existing architecture. These Web services are secured using Forms Authentication. Hence, we need to turn the default behavior of Forms Authentication (redirects to login pages, etc)...
5
2561
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 "Enlighten.LinkMad.Businesslogic". In one of my frontend websites I use this type to authenticate a user who is trying to login. The following excerpt is from the web.config of the particular site showing the reference to the custom provider, allowing .Net to do...
6
7034
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 {...}
6
2339
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 having to do a httpwebreqeust call.
1
4423
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 intended for use, but I think this is the only solution for my situation. I searched the web, in the hope finding the answer, without any luck, so my final hope is with you. Let me explain the situation: I have an 'export'-wrapper to my regular...
2
2102
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 original author of the below post) I have similar issue sharing types between the web services, and also the client consuming those web services. I have all my custom types defined in a seperate assembly and I am using those types as parameter/...
2
1067
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 complains about( You must implement a default accessor as it inherits from ICollection). I want to now what are the methods need to be implemented for that collection.Any help with sample code is highly appreciated. Thanks
9
3808
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 techniques are not feasible) The question is; Given that I have a Person object with a private set for id. What is the recommended approac in passing that object to the web service
1
20413
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 (C#); public class MyServiceInstaller : System.Configuration.Install.Installer { private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller;
0
9810
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
9653
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10524
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...
1
10562
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10236
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
6968
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
5805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4434
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
3
3092
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.