WS Serialization of ArrayList derived Class

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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,...
    2. 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...
    3. #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: ...
    4. #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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139