Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:45:36+00:00 2026-06-14T11:45:36+00:00

I’ve got the following chunk of XML data: <ArrayOfRESTDataSource xmlns=http://SwitchKing.Common/Entities/RESTSimplified/2010/07 xmlns:i=http://www.w3.org/2001/XMLSchema-instance> <RESTDataSource> <Description>MyTest</Description> <Enabled>true</Enabled>

  • 0

I’ve got the following chunk of XML data:

<ArrayOfRESTDataSource xmlns="http://SwitchKing.Common/Entities/RESTSimplified/2010/07" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<RESTDataSource>
    <Description>MyTest</Description>
    <Enabled>true</Enabled>
 </RESTDataSource>
</ArrayOfRESTDataSource>

RESTDataSource can occur 0-n times.

And here’s my classes:

[DataContract( Namespace = "http://SwitchKing.Common/Entities/RESTSimplified/2010/07" )]
public class ArrayOfRESTDataSource
{
    public RESTDataSource[] Data { set; get; }  
}


[DataContract( Namespace = "http://SwitchKing.Common/Entities/RESTSimplified/2010/07" )]
public class RESTDataSource
{
    [DataMember]
    public bool Enabled { get; set; }
    [DataMember]
    public string Description { get; set; }
}

I read the above XML data from a server like this:

WebRequest client = WebRequest.Create( "http://server:80/datasources" );
using( StreamReader sr = new StreamReader( client.GetResponse().GetResponseStream()) ) {
    string xml = sr.ReadToEnd();
var response = ServiceStack.Text.XmlSerializer.DeserializeFromString<ArrayOfRESTDataSource>( xml );
}

My question is: What do I need to change or decorate public RESTDataSource[] Data with to get the deseralization to work for the array? Serializing single RESTDataSource items work just fine, its just the array I can’t get to work.

Thanks in advance.

Update 1

As @mythz suggested, I updated my code to this, but response.Data is still null. What did I not understand?

[DataContract( Namespace = "http://SwitchKing.Common/Entities/RESTSimplified/2010/07" )]
 public class ArrayOfRESTDataSource
{
    [DataMember]
    public DataSource Data { set; get; }
}

[CollectionDataContract( ItemName = "RESTDataSource" )]
public class DataSource : List<RESTDataSource>
{
    public DataSource() { }
    public DataSource( IEnumerable<RESTDataSource> collection ) : base( collection ) { }
}

Update 2

The solution is in @mythz answer below, but just for completeness/clarity: What I did wrong was to add another level in my DTOs – the top-level class ArrayOfRESTDataSource is the one that actually has the sub items in XML so it is that one that should be of a collection type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:45:37+00:00Added an answer on June 14, 2026 at 11:45 am

    You can use [CollectionDataContract(...)] to modify the serialization output for Arrays/Collections, see this previous answer for an example.

    Debugging Serialization and Integration issues

    The first step when trying to solve integration problems like this is to isolate the problem. i.e. remove everything else away and just focus on the problem. e.g. In this case I would just focus on the XML and the DTOs and decouple them from your services.

    ServiceStack just uses .NET’s Xml DataContractSerializer under the hood and doesn’t add any extra transformations or byte overheads (it’s just the raw DTOs serialized as-is), so if you can get it working outside of your services you can put the same DTOs back into your service and it will also work over the wire.

    Handy ServiceStack Extension methods

    ServiceStack provides convenient extension methods to serialize / de-serialize and analyze your data models:

    Serialization / De-Serialization Extension methods

    T.ToJson() / string.FromJson<T>()  //Serialize JSON
    T.ToJsv() / string.FromJsv<T>()    //Serialize JSV  
    T.ToXml() / string.FromXml<T>()    //Serialize XML
    

    Handy Dump Utils

    Recursively print a object-graph in Pretty JSV Dump Format

    T.PrintDump()      
    

    Print a string to the console resolving string.Format() args (if any)

    string.Print(args)    
    

    What do your Serialized DTOs look like

    The first step you should be doing when trying to come up with the Shape of the DTOs is to populate and print them to see what it looks like. Looking at the chunk of XML output I came up with these DTOs:

    [DataContract(Namespace = "http://SwitchKing.Common/Entities/RESTSimplified/2010/07")]
    public class RESTDataSource
    {
        [DataMember]
        public bool Enabled { get; set; }
        [DataMember]
        public string Description { get; set; }
    }
    
    [CollectionDataContract(ItemName = "RESTDataSource", Namespace = "http://SwitchKing.Common/Entities/RESTSimplified/2010/07")]
    public class ArrayOfRESTDataSource : List<RESTDataSource>
    {
        public ArrayOfRESTDataSource() { }
        public ArrayOfRESTDataSource(IEnumerable<RESTDataSource> collection) : base(collection) { }
    }
    

    Then populate and dump them:

    var dto = new ArrayOfRESTDataSource { 
        new RESTDataSource { Enabled = true, Description = "MyTest" } };
    
    dto.ToXml().Print();
    

    Which prints to the Console:

    <?xml version="1.0" encoding="utf-8"?><ArrayOfRESTDataSource xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://SwitchKing.Common/Entities/RESTSimplified/2010/07"><RESTDataSource><Description>MyTest</Description><Enabled>true</Enabled></RESTDataSource></ArrayOfRESTDataSource>
    

    Which looks like what we want. If it doesn’t tweak the above DTOs until you get the same chunk as your expected XML.

    When you have the DTOs in the same shape of the XML you can start trying to serialize them:

    var dto = xml.FromXml<ArrayOfRESTDataSource>();
    dto.PrintDump();
    

    Which will print this pretty object graph:

    [
        {
            Enabled: True,
            Description: MyTest
        }
    ]
    

    If all the fields are populated with the expected values then you are done and can update your ServiceStack web service DTOs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.