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

  • Home
  • SEARCH
  • 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 63787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:41:16+00:00 2026-05-10T18:41:16+00:00

This is a very complicated question concerning how to serialize data via a web

  • 0

This is a very complicated question concerning how to serialize data via a web service call, when the data is not-strongly typed. I’ll try to lay it out as best possible.

Sample Storage Object:

[Serializable] public class StorageObject {   public string Name { get; set; }   public string Birthday { get; set; }   public List<NameValuePairs> OtherInfo { get; set; }   } [Serializable]    public class NameValuePairs {   public string Name { get; set; }   public string Value { get; set; } } 

Sample Use:

[WebMethod]     public List<StorageObject> GetStorageObjects() {       List<StorageObject> o = new List<StorageObject>() {         new StorageObject() {            Name = 'Matthew',           Birthday = 'Jan 1st, 2008',            OtherInfo = new List<NameValuePairs>() {             new NameValuePairs() { Name = 'Hobbies', Value = 'Programming' },             new NameValuePairs() { Name = 'Website', Value = 'Stackoverflow.com' }           }         },         new StorageObject() {            Name = 'Joe',           Birthday = 'Jan 10th, 2008',           OtherInfo = new List<NameValuePairs>() {              new NameValuePairs() { Name = 'Hobbies', Value = 'Programming' },             new NameValuePairs() { Name = 'Website', Value = 'Stackoverflow.com' }           }         }       };        return o;     } 

Return Value from Web Service:

<StorageObject>     <Name>Matthew</Name>     <Birthday>Jan 1st, 2008</Birthday>     <OtherInfo>         <NameValuePairs>             <Name>Hobbies</Name>             <Value>Programming</Value>         </NameValuePairs>         <NameValuePairs>             <Name>Website</Name>             <Value>Stackoverflow.com</Value>         </NameValuePairs>     </OtherInfo> </StorageObject> 

What I want:

<OtherInfo>     <Hobbies>Programming</Hobbies>     <Website>Stackoverflow.com</Website> </OtherInfo> 

The Reason & Other Stuff:

First, I’m sorry for the length of the post, but I wanted to give reproducible code as well.

I want it in this format, because I’m consuming the web services from PHP. I want to easily go:

// THIS IS IMPORANT

In PHP => '$Result['StorageObject']['OtherInfo']['Hobbies']'.   

If it’s in the other format, then there would be no way for me to accomplish that, at all. Additionally, in C# if I am consuming the service, I would also like to be able to do the following:

// THIS IS IMPORANT

In C# => var m = ServiceResult[0].OtherInfo['Hobbies']; 

Unfortunately, I’m not sure how to accomplish this. I was able to get it this way, by building a custom Dictionary that implemented IXmlSerializer (see StackOverflow: IXmlSerializer Dictionary), however, it blew the WSDL schema out of the water. It’s also much too complicated, and produced horrible results in my WinFormsTester application!

Is there any way to accomplish this ? What type of objects do I need to create ? Is there any way to do this /other than by making a strongly typed collection/ ? Obviously, if I make it strongly typed like this:

public class OtherInfo {   public string Hobbies { get; set; }   public string FavoriteWebsite { get; set; } } 

Then it would work perfectly, I would have no WSDL issues, I would be able to easily access it from PHP, and C# (.OtherInfo.Hobbies).

However, I would completely lose the point of NVP’s, in that I would have to know in advance what the list is, and it would be unchangeable.. say, from a Database.

Thanks everyone!! I hope we’re able to come up with some sort of solution to this. Here’s are the requirements again:

  1. WSDL schema should not break
  2. Name value pairs (NVP’s) should be serialized into attribute format
  3. Should be easy to access NVP’s in PHP by name [‘Hobbies’]
  4. Should be easy to access in C# (and be compatible with it’s Proxy generator)
  5. Be easily serializable
  6. Not require me to strongly type the data

Now, I am /completely/ open to input on a better/different way to do this. I’m storing some relatively ‘static’ information (like Name), and a bunch of pieces of data. If there’s a better way, I’d love to hear it.

  • 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. 2026-05-10T18:41:17+00:00Added an answer on May 10, 2026 at 6:41 pm

    This is like dynamic properties for a object. C# is not quite a dynamic language unlike javascript or maybe PHP can parse the object properties on the fly. The following two methods are what I can think of. The second one might fit into your requirements.

    The KISS Way

    The Keep It Simple Stupid way

    public class StorageObject {   public string Name { get; set; }   public string Birthday { get; set; }   public List<string> OtherInfo { get; set; }   } 

    You can have name value pairs which is separated by ‘|’

    OtherInfo = {'Hobbies|Programming', 'Website|Stackoverflow.com'} 

    Serialized forms

    <StorageObject>     <Name>Matthew</Name>     <Birthday>Jan 1st, 2008</Birthday>     <OtherInfo>         <string>Hobbies|Programming</string>         <string>Website|Stackoverflow.com</string>     </OtherInfo> </StorageObject> 

    The Dynamic Way in C#

    Make the name value pair part become an XML element so that you can build it dynamically.

    public class StorageObject {   public string Name { get; set; }   public string Birthday { get; set; }   public XElement OtherInfo { get; set; } // XmlElement for dot net 2 } 

    You can easily build up OtherInfo object as element centric e.g.

    XElement OtherInfo = new XElement('OtherInfo'); OtherInfo.Add( ..Hobbies xelement & text value..); OtherInfo.Add( ..WebSite xelement & text value..); 

    The serialized form will be

    <OtherInfo>     <Hobbies>Programming</Hobbies>     <Website>Stackoverflow.com</Website> </OtherInfo> 

    or build it as attribute centric

    XElement OtherInfo = new XElement('OtherInfo'); OtherInfo.Add( ..nvp xattribute Hobbies & value..); OtherInfo.Add( ..nvp xattribute WebSite & value..);  <OtherInfo>     <nvp n='Hobbies' v='Programming' />     <nvp n='Website' v='Stackoverflow.com' /> </OtherInfo> 

    For any dynamic language, it can access to the properties directly. For the rest, they can access the value by read the XML. Reading XML is well supported by most of framework.

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

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Typo. Nothing More. No such protocol exists. What you are… May 11, 2026 at 9:52 am
  • added an answer Yes. For starts implement NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler) and then use something like… May 11, 2026 at 9:52 am
  • added an answer Calling the reloadData method refreshes the data as soon as… May 11, 2026 at 9:52 am

Related Questions

This is a very complicated question concerning how to serialize data via a web
This is a very specific question regarding MySQL as implemented in WordPress . I'm
This is a very simple question with a simple answer, but it is not
This is a very basic question. I'm just on my mission to learn ASP.NET
I am sure this is a very simple problem, but I am new to
I realise that this is a very basic question, but it is one which
I'm a very novice OCaml programmer so please forgive me if this is a
Even before telling my question, will tell you that this is a very vague
I know this is a darn simple question, but I'm very used to using
This is mostly a theoretical question I'm just very curious about. (I'm not trying

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.