Results 1 to 3 of 3

Thread: Which collections object (like dictionary, List ) to use in a web service to serializ

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    211

    Which collections object (like dictionary, List ) to use in a web service to serializ

    I am building a webservice (not WCF). I need to store two values (name,value pairs) in a method.

    Instead of using List<string>, I used Dictionary<string,int>. But it gives me error message saying "Can't serialize the dictionary object.

    Which collections object I can use (to be able to serialize) to store name value pair in a webservice .

    Thanks much

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Which collections object (like dictionary, List ) to use in a web service to seri

    It took me less than a minute on the web to find this as a solution to the issue that .NET objects that implement IDictionary cannot be serialised:

    http://weblogs.asp.net/pwelter34/arc...03/444961.aspx

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    211

    Re: Which collections object (like dictionary, List ) to use in a web service to seri

    Before posting, I googled and came to know that Dictionary object is not serializable. came across the following way to do:

    using System;
    using System.Collections.Generic;

    class Program
    {
    static void Main()
    {
    // Shows a List of KeyValuePairs.
    var list = new List<KeyValuePair<string, int>>();
    list.Add(new KeyValuePair<string, int>("Cat", 1));
    list.Add(new KeyValuePair<string, int>("Dog", 2));
    list.Add(new KeyValuePair<string, int>("Rabbit", 4));

    foreach (var element in list)
    {
    Console.WriteLine(element);
    }
    }
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width