Ask a Question related to ASP.NET Web Services, Design and Development.
-
MSFT #1
RE: WS Serialization of ArrayList derived Class
Hi Steve,
You may refer to this article to see if it will help:
Controlling XML Serialization Using Attributes
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
l/cpconcontrollingserializationbyxmlserializerwithat tributes.asp
Luke
Microsoft Online Support
Get Secure! [url]www.microsoft.com/security[/url]
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
MSFT Guest
-
Derived class not exposed in XML
Say I have a class inherited from ArrayList called MyCollection. I have a WebMethod that returns a MyCollection. But when I reference the service,... -
Passing a derived class to a WebMethod
I am writing a client that consumes a web service and extends the functionality of one of the web service's classes. The definition is something... -
#26325 [Bgs->Opn]: At least a notice when accessing private members in a derived class?
ID: 26325 User updated by: drm at melp dot nl Reported By: drm at melp dot nl -Status: Bogus +Status: ... -
#26325 [Opn->Bgs]: At least a notice when accessing private members in a derived class?
ID: 26325 Updated by: jay@php.net Reported By: drm at melp dot nl -Status: Open +Status: Bogus Bug... -
Access DataGrid declared in derived class from base class??
Hi! I have a base class called ListBase.vb, from which I derive EmplList.ascx.vb. In EmplList.ascx.vb I declared a... -
Steven Livingstone #2
Re: WS Serialization of ArrayList derived Class
Hi Luke - thanks for your post.
I had browsed that article yesterday at some point and it doesn't solve my issue.
I even tried making the return value public as shown in the following code in my asmx :
[XmlArray("AItems")]
[XmlArrayItem("AItem", typeof(ItemA))]
public ItemACollection a;
[WebMethod]
public ItemACollection GetCols()
{
a = new ItemACollection();
return a;
}
and the following in the ItemACollection class :
using System;
using System.Collections;
using System.Xml.Serialization;
namespace myns
{
public class ItemACollection : ArrayList {}
}
If it try to type the ItemACollection class with [XmlType("ItemACollection")] then i get an exception saying "There was an error reflecting type..."
Otherwise I still get ArrayOfItemA. It seems the problem is that you are unable to control...
[a] The name of the root element in an custom component derived from arraylist (i never tried other collection types)
[b] The name of the items within that collection when they are serialized as part of the arraylist. However, returning a single instance directly (i.e. not as part of the arraylist derived class) works fine and returns the custom root name. [I didn't show this part in the code above, but i have tried that locally].
It is not a massive issue, but unless i am missing something seems an oversight which would mean you would have to define your schemas around the names of your classes in some cases; rather than custom element names.
In fact (if you are still reading!) if you define a property in the above collection that takes a collection of ItemB instances (say, called ItemBCollection), then when serialzied it DOES allow you to properly output your custom element names for the collection element node and each item within that collection. It just seems that this does not apply at the top level collection.
If you get 5 mins i urge you to create two simple classes derived from ArrayList and try to serialize them. I hope you can do it and I am missing something, but it seems less likely the more i try.
Best Wishes,
Steven
Steven Livingstone Guest
-
MSFT #3
Re: WS Serialization of ArrayList derived Class
Hi Steve,
Sorry for replying later. You may try following:
[WebMethod]
[return:XmlRoot("MyRoot")]
public ItemACollection GetCols()
{
ItemACollection ItemACol = new ItemACollection();
return ItemACol ;
}
Does this resolve the problem?
Luke
Microsoft Online Support
Get Secure! [url]www.microsoft.com/security[/url]
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
MSFT Guest



Reply With Quote

