473,387 Members | 1,362 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,387 software developers and data experts.

Passing a collection of objects from a web service

Hi. I am attempting something new in my coding and need some direction. I
have a web service that I am attempting to return a custom colleciton of
custom objects of a single type.

When I call the web method from a client host I am getting back a
1-dimensional array and I can't convert each item in the array to the
appropriate custom type that is exposed in the array.

Can any body provide me some direction on how I should be passing back a
collection of custom objects from a web service?

Any help would be appreciated.
--
Malcolm Robinson
Nov 23 '05 #1
3 5642
Malcom

In some cases the WSDL.exe program that generates your proxy class
follows a least-common-denominator policy when casting objects from the
returned from the webmethod. For example, an ArrayList object returned
from a webmethod would be converted to an object array in your
auto-generated proxy.

This isn't to big of an issue as once the proxy has been generated, you
can simply override the object type manually. Here's an example.

Say we were trying to generate the proxy for the following method

string DummyMethod(System.Collections.ArrayList intList)

After running the wsdl.exe, we would have the following proxy

public string DummyMethod(object[] intList) {
object[] results = this.Invoke("DummyMethod", new object[]
{
intList});
return ((string)(results[0]));
}

public System.IAsyncResult BeginDummyMethod(object[] intList,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DummyMethod", new object[] {
intList}, callback, asyncState);
}
As you can see, our arraylist is now represented as an object array in
our proxy. What you have to do in this case, is modify the parameters
of the methods to use the original arraylist.

public string DummyMethod(System.Collections.ArrayList intList) {
object[] results = this.Invoke("DummyMethod", new object[]
{
intList});
return ((string)(results[0]));
}

public System.IAsyncResult
BeginDummyMethod(System.Collections.ArrayList intList,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DummyMethod", new object[] {
intList}, callback, asyncState);
}

You should be able to follow this example to return your custom object
collection.

Hope that helps

Peter Kelcey

Nov 23 '05 #2
Malcom

In some cases the WSDL.exe program that generates your proxy class
follows a least-common-denominator policy when casting objects from the
returned from the webmethod. For example, an ArrayList object returned
from a webmethod would be converted to an object array in your
auto-generated proxy.

This isn't to big of an issue as once the proxy has been generated, you
can simply override the object type manually. Here's an example.

Say we were trying to generate the proxy for the following method

string DummyMethod(System.Collections.ArrayList intList)

After running the wsdl.exe, we would have the following proxy

public string DummyMethod(object[] intList) {
object[] results = this.Invoke("DummyMethod", new object[]
{
intList});
return ((string)(results[0]));
}

public System.IAsyncResult BeginDummyMethod(object[] intList,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DummyMethod", new object[] {
intList}, callback, asyncState);
}
As you can see, our arraylist is now represented as an object array in
our proxy. What you have to do in this case, is modify the parameters
of the methods to use the original arraylist.

public string DummyMethod(System.Collections.ArrayList intList) {
object[] results = this.Invoke("DummyMethod", new object[]
{
intList});
return ((string)(results[0]));
}

public System.IAsyncResult
BeginDummyMethod(System.Collections.ArrayList intList,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DummyMethod", new object[] {
intList}, callback, asyncState);
}

You should be able to follow this example to return your custom object
collection.

Hope that helps

Peter Kelcey

Nov 23 '05 #3
Thanks Peter, I will take a look at this and see if it helps resolve my
issue. I appreciate your help.

--
Malcolm Robinson
"Peter Kelcey" wrote:
Malcom

In some cases the WSDL.exe program that generates your proxy class
follows a least-common-denominator policy when casting objects from the
returned from the webmethod. For example, an ArrayList object returned
from a webmethod would be converted to an object array in your
auto-generated proxy.

This isn't to big of an issue as once the proxy has been generated, you
can simply override the object type manually. Here's an example.

Say we were trying to generate the proxy for the following method

string DummyMethod(System.Collections.ArrayList intList)

After running the wsdl.exe, we would have the following proxy

public string DummyMethod(object[] intList) {
object[] results = this.Invoke("DummyMethod", new object[]
{
intList});
return ((string)(results[0]));
}

public System.IAsyncResult BeginDummyMethod(object[] intList,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DummyMethod", new object[] {
intList}, callback, asyncState);
}
As you can see, our arraylist is now represented as an object array in
our proxy. What you have to do in this case, is modify the parameters
of the methods to use the original arraylist.

public string DummyMethod(System.Collections.ArrayList intList) {
object[] results = this.Invoke("DummyMethod", new object[]
{
intList});
return ((string)(results[0]));
}

public System.IAsyncResult
BeginDummyMethod(System.Collections.ArrayList intList,
System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DummyMethod", new object[] {
intList}, callback, asyncState);
}

You should be able to follow this example to return your custom object
collection.

Hope that helps

Peter Kelcey

Nov 23 '05 #4

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

Similar topics

5
by: John Dewbert | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Hello, I have trouble passing a folder object (from a FileSystemObject) to a sub procedure. Consider the following code: ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
25
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business...
1
by: vbvjain | last post by:
I am developing an applocation which reads mails in outlook inbo alongwith attachments and all these informmation is stored in collection which i need to pass it to a web service, which will perfor...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
3
by: Dave | last post by:
Please - anyone that can help. I am getting confusing results while trying to expose a collection from a web service. I have a webservice in which a web method accepts a collection as a...
18
by: Larry Herbinaux | last post by:
I'm having issues with garbage collection with my long-standing service process. If you could review and point me in the right direction it would be of great help. If there are any helpful...
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...
2
by: =?Utf-8?B?Y3Nz?= | last post by:
I am new to ASP.net webservice and have a quesiton. Is is possible to pass custom object to a web service (using VB 2005)? My custom object will look like this Public Class Myclass Public...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.