WebServices Return DataSet + String as Objec

S

SMG

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

Now I want to return two things,
1. DataSet
2. String

through one request only, I thot of using ArrayList 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 AraryList it didn't work with that, it says "Object must
implement IConvertible."

ArrayList arrL = new ArrayList();
arrL.Add((object)Token);
arrL.Add((object)returnDataSet);

Any Idea how do we use and consume the same.

Regards,
Shailesh Gajare
 
I

Ingo Eichenseher

Why not create a class like:

public class ReturnValue
{
public DataSet ds;
public string str;
}

and return that.

Ingo
 
S

SMG

Thanks Ingo,
But the one who is using my webservices I need to tell them that I am
sending a ReturnValue class object.
How can they consume the same? Can any one provide a sample code or a link
which explains this.

If I do this way, can any one use my webservices e.g. Java, .Net . any other
application language. what are the precautions I should take for the same so
that everyone can use my webservice.

Do they need to type cast it to ReturnValue class again and then they will
separate it out the string and dataset and use it in their application.

what are best practices suggested for this.

Regards,
Shailesh G



Why not create a class like:

public class ReturnValue
{
public DataSet ds;
public string str;
}

and return that.

Ingo
 
I

Ingo Eichenseher

I think anyone will be able to consume the webservice.
The most complicated task is consuming the DataSet
not the class ReturnValue.

The class will be serialized as a simple XML-structure like:

<ReturnValue>
<ds></ds>
<str></str>
</ReturnValue>

the DataSet however will be serizialized as 'DiffGram'
which is not so easy to be serialized without .net.

I would consider using simply a XmlDocument or XmlNode
instead of the DataSet in this case. On the .net side
it's easy to convert DataSet to XmlDocument and vice-versa.

Ingo
 
S

SMG

Hi Ingo,

My werbservice has to return two values(1.string , 2.DataSet). As per your
suggestion I created one class which has two params and my WebMethod
(GetAuthenticated) returns an object of ReturnValue.

But when i try to consume the webservice it says
Cannot convert type 'WebServices.Shaileshpc.ReturnValue' to
'WebServices.Consume.ReturnValue'

'WebServices.Shaileshpc.ReturnValue' : namespace of webservice
'WebServices.Consume.ReturnValue'

------------------------
[WebMethod]
public ReturnValue GetAuthenticated(string sLoginName, string sPassword)
{
ReturnValue newPassObj = new ReturnValue();
ShareKhan.PmsComponents.PmsBase checkLogin = new
ShareKhan.PmsComponents.PmsEq();
newPassObj.TokenCode = (checkLogin.WS_SignIn("abc","abc")).ToString();
if (newPassObj.TokenCode != "00000000-0000-0000-0000-000000000000" )
{
returnDataSet = checkLogin.WS_UserInfo(new Guid(Token));
}
newPassObj.DataInformation = returnDataSet;
return newPassObj;
}
------------------------
public class ReturnValue
{
private string Token;
private DataSet returnDataSet1 = null;
public DataSet DataInformation
{
get {return returnDataSet1; }
set {returnDataSet1 = value; }
}
public string TokenCode
{
get {return Token;}
set {Token = value;}
}
}
------------------------
Consume.aspx has following code :
Shaileshpc.PortfolioManager obj = new Shaileshpc.PortfolioManager();
* ReturnValue objNewPass = (ReturnValue)obj.GetAuthenticated(TextBox1.Text,
TextBox2.Text);

Note : * is the error line


Regards,
Shailesh Gajare

I think anyone will be able to consume the webservice.
The most complicated task is consuming the DataSet
not the class ReturnValue.

The class will be serialized as a simple XML-structure like:

<ReturnValue>
<ds></ds>
<str></str>
</ReturnValue>

the DataSet however will be serizialized as 'DiffGram'
which is not so easy to be serialized without .net.

I would consider using simply a XmlDocument or XmlNode
instead of the DataSet in this case. On the .net side
it's easy to convert DataSet to XmlDocument and vice-versa.

Ingo
 
I

Ingo Eichenseher

Hi,

do not define the class ReturnValue in your client.

If you add a Web-reference to your client the
class will be generated automatically but in the Namespace
of your Proxy-Class.

Just use 'WebServices.Shaileshpc.ReturnValue' in the client.

Ingo
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top