how to make webmethod output my object class?

X

xisco

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
 
X

xisco

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

Josh Twist

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/
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top