how to make webmethod output my object class?

Discussion in 'ASP .Net Web Services' started by xisco, Feb 13, 2006.

  1. xisco

    xisco Guest

    hi,
    I want to make my webmethod return my defined object and later it will be
    consumed by a java client, so I did this very simple test.
    In the webmethod I do:
    [WebMethod]
    public myClass GetMyClass()
    {
    myClass output = new myClass();
    return output;
    }

    and this is my class:
    public myClass : ISerializable
    {
    public myClass()
    {
    }

    private int _item1 = -1;
    public int Item1
    {
    get{return _item1;}
    set{_item1 = value;}
    }

    private HashTable _list1 = new HastTable()
    public HashTable List1
    {
    get{return _list1;}
    set{_list1 = value;}
    }

    void ISerializable.GetObjectData( SerializationInfo info,
    StreamingContex context)
    {
    info.SetType(typeof(myClass));
    }
    }

    but this is not working. What I am missing here? is this the correct
    approach?

    Xis
    xisco, Feb 13, 2006
    #1
    1. Advertising

  2. xisco

    xisco Guest

    BTW, the problem is that I get a message telling that HashTable can not be
    serialized.



    "xisco" <> wrote in message
    news:u8zsf$...
    > hi,
    > I want to make my webmethod return my defined object and later it will be
    > consumed by a java client, so I did this very simple test.
    > In the webmethod I do:
    > [WebMethod]
    > public myClass GetMyClass()
    > {
    > myClass output = new myClass();
    > return output;
    > }
    >
    > and this is my class:
    > public myClass : ISerializable
    > {
    > public myClass()
    > {
    > }
    >
    > private int _item1 = -1;
    > public int Item1
    > {
    > get{return _item1;}
    > set{_item1 = value;}
    > }
    >
    > private HashTable _list1 = new HastTable()
    > public HashTable List1
    > {
    > get{return _list1;}
    > set{_list1 = value;}
    > }
    >
    > void ISerializable.GetObjectData( SerializationInfo info,
    > StreamingContex context)
    > {
    > info.SetType(typeof(myClass));
    > }
    > }
    >
    > but this is not working. What I am missing here? is this the correct
    > approach?
    >
    > Xis
    >
    xisco, Feb 13, 2006
    #2
    1. Advertising

  3. xisco

    Josh Twist Guest

    I think the problem is because your inherits ISerializable - but the
    hashtable can't be serialized. If you remove the derived class you
    won't have the problem. Does your class have to be serializable? (If
    does, you can't have a Hashtable publicly accessible).

    Josh
    http://www.thejoyofcode.com/
    Josh Twist, Feb 13, 2006
    #3
  4. xisco

    xisco Guest

    yes, that was the problem. I will find another collection for it then.
    thanks

    Xis

    "Josh Twist" <> wrote in message
    news:...
    >I think the problem is because your inherits ISerializable - but the
    > hashtable can't be serialized. If you remove the derived class you
    > won't have the problem. Does your class have to be serializable? (If
    > does, you can't have a Hashtable publicly accessible).
    >
    > Josh
    > http://www.thejoyofcode.com/
    >
    xisco, Feb 14, 2006
    #4
    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. Ryan Bingham

    Can't return class instance from WebMethod

    Ryan Bingham, Aug 11, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    105
    Ryan Bingham
    Aug 11, 2003
  2. Q
    Replies:
    0
    Views:
    121
  3. WebMethod returning a object in a COM dll

    , Feb 16, 2005, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    107
    Keenan Newton
    Feb 17, 2005
  4. RCS
    Replies:
    3
    Views:
    147
  5. MuZZy
    Replies:
    1
    Views:
    160
    Steven Cheng[MSFT]
    Mar 24, 2006
Loading...

Share This Page