WebServices Return DataSet + String as Object

S

SMG

Hi All,
I have a Web Service, which returns a DataSet and I am able to consume.
This is ok.

Now I want to return two things,
1. DataSet
2. String
Through one request only, I thot of using object as a return type to the
webservices but then how do I re cast it to string and dataset. Will that
work.
I tried with object array it didn't work with that, it says "implement
IConvertible"

Any Idea how do we use and consume the same.

Regards,
Shailesh Gajare
 
G

Guest

Hi SMG,

you could add another table to the DataSet, which holds the string
reference. Or you can (as you described) a object-array:

....
return (new object [] { myStringValue , myDataSet });
....

You can read it as follows:
if (myResult != null && myResult.Length == 2)
{
localDataSet = myResult [1];
localString = myResult [0];

// do something you want with the references
}

Regards
Patrick
 
J

JD

You could always return a class. The code below shoe show the idea.

Class ReturnMe
public DS as Dataset
public Str as string
end class

class WebServiceClas()
.....
<webmethod> public function ReturnData(...) as ReturnMe
......
end class
 
S

SMG

Thanks JD

But for that, the end user who are using my webservices should be aware of
such classes or I need to give that class file as well along with the
description of the web service.

Is it the right way to do it?
what does Best Practices suggest?

Regards,
Shailesh



You could always return a class. The code below shoe show the idea.

Class ReturnMe
public DS as Dataset
public Str as string
end class

class WebServiceClas()
.....
<webmethod> public function ReturnData(...) as ReturnMe
......
end class
 
J

JD

The class will be exposed to the users, once you have your webmethod
return the class back.
Users code:
(make sure once you compile you webservice to update your web ref)
Dim a as new WebServ.WebServiceClas

'This will be automatically created in the WSDL
Dim b as ReturnMe

b = a.ReturnData()
'Do whatever and refernce you want to the objects
b.DS()
b.Str

As far as Best Practice I'm not sure, I need to retrieve about 6 pieces
of data, orginally tried structure but that didn't work, but found an
article on microsoft that suggeted using this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top