WebServices Return DataSet + String as Objec

Discussion in 'ASP .Net Web Services' started by SMG, Apr 22, 2005.

  1. SMG

    SMG Guest

    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
    SMG, Apr 22, 2005
    #1
    1. Advertising

  2. Why not create a class like:

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

    and return that.

    Ingo
    Ingo Eichenseher, Apr 24, 2005
    #2
    1. Advertising

  3. SMG

    SMG Guest

    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



    "Ingo Eichenseher" <> wrote in message
    news:#...
    Why not create a class like:

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

    and return that.

    Ingo
    SMG, Apr 25, 2005
    #3
  4. 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
    Ingo Eichenseher, Apr 25, 2005
    #4
  5. SMG

    SMG Guest

    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

    "Ingo Eichenseher" <> wrote in message
    news:...
    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
    SMG, Apr 25, 2005
    #5
  6. 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
    Ingo Eichenseher, Apr 27, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer
    Replies:
    0
    Views:
    447
    Kevin Spencer
    Jun 30, 2003
  2. SMG
    Replies:
    4
    Views:
    3,524
  3. Replies:
    2
    Views:
    12,739
    Sean Foy
    Aug 6, 2006
  4. Replies:
    2
    Views:
    376
    Thommy
    Oct 29, 2008
  5. Samuel
    Replies:
    8
    Views:
    113
    [MSFT]
    Oct 14, 2004
Loading...

Share This Page