Re: problems returning ArrayList from webServices
From: Mickey Williams (my)
Date: 04/13/04
- Next message: Nicholas Stamos: "Re: Server did not recognize the value of HTTP Header SOAPAction"
- Previous message: Mickey Williams: "Re: Hashtables And Webservices"
- In reply to: Mario Rodriguez: "problems returning ArrayList from webServices"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 13 Apr 2004 09:24:04 -0700
You have two problems:
- Collections are always serialized as simple arrays.
- The general-purpose collection classes in the framework are only typed to
work with object.
If you return an instance of a type that will cause other types to be
serialized polymorphically, you must use SoapInclude or XmlInclude
attributes to include the proper runtime type information.
If you want to serialize as a specific collection class rather than just an
array, wrap it. So if you had a class called Boat, and a strongly-typed
collection called BoatCollection, define your web method like:
[WebMethod]
public BoatRet GetBoats()
{
BoatRet ret = new BoatRet();
ret.Boats.Add(...);
ret.Boats.Add(...);
ret.Boats.Add(...);
return ret;
}
class BoatRet
{
BoatCollection _boats = new BoatCollection();
public BoatCollection Boats
{
get { return _boats; }
}
}
-- Mickey Williams Author, "Microsoft Visual C# .NET Core Reference", MS Press www.servergeek.com "Mario Rodriguez" <mrodriguez@avantica.net> wrote in message news:eaEbN9MIEHA.2144@TK2MSFTNGP12.phx.gbl... > Hi, I'm in a big problem because my implementation of a webService that > returns an ArrayList object have a weird behaviour. On the client side, > instead of return an ArrayList object, returns an object[] !!!!. This is > normal or correct ???????? > > My other problem is that the ArrayList (and object[]) contains references to > an object My Container, that is out the namespace of the webService (so I've > to add the reference to MyContainer in both the client side and the > webService) but on the client side, when I try read the objects from the > object[] I got a castException due to the objectArray contains instances of > webService.namespace.MyContainer and not of > myContainer.namespace.MyContainer. > > I'm not sure what is happening in both situations, that if someone can give > me a helping hand, I'll thank you a lot > >
- Next message: Nicholas Stamos: "Re: Server did not recognize the value of HTTP Header SOAPAction"
- Previous message: Mickey Williams: "Re: Hashtables And Webservices"
- In reply to: Mario Rodriguez: "problems returning ArrayList from webServices"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|