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 6126137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:20:03+00:00 2026-05-23T16:20:03+00:00

I have a method: [WebGet] [OperationContract] public int CollabSortFolder(int FolderId, Dictionary<int, int> Items) {

  • 0

I have a method:

[WebGet]
[OperationContract]
public int CollabSortFolder(int FolderId, Dictionary<int, int> Items)
{

    Console.Write(Items);
    return -1;
}

If I try this url:

http://server/CollabSortFolder?FolderId=12&Items={"1":3,"4":5,"6":7}

Items.Count is 0

What is the proper syntax to get my Dictionary filled?

  • 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-05-23T16:20:04+00:00Added an answer on May 23, 2026 at 4:20 pm

    You can customize the deserialization of a query string parameter by writing a custom QueryStringConverter for your service. The code below shows one which can understand the format you have in your question.

    public class StackOverflow_6630425
    {
        [ServiceContract]
        public class Service
        {
            [WebGet]
            public string CollabSortFolder(int FolderId, Dictionary<int, int> Items)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("FolderId=" + FolderId);
                foreach (var key in Items.Keys)
                {
                    sb.AppendLine(string.Format("  Items[{0}] = {1}", key, Items[key]));
                }
                return sb.ToString();
            }
        }
        public class MyQueryStringConverter : QueryStringConverter
        {
            public override bool CanConvert(Type type)
            {
                return type == typeof(Dictionary<int, int>) || base.CanConvert(type);
            }
    
            public override object ConvertStringToValue(string parameter, Type parameterType)
            {
                if (parameterType == typeof(Dictionary<int, int>))
                {
                    parameter = parameter.Trim().Substring(1, parameter.Length - 2); // trimming the begin and end '{' / '}'
                    string[] pairs = parameter.Split(',');
                    Dictionary<int, int> result = new Dictionary<int, int>();
                    foreach (string pair in pairs)
                    {
                        string[] parts = pair.Split(':');
                        string key = parts[0].Trim();
                        string value = parts[1].Trim();
                        if (key.StartsWith("\"")) key = key.Substring(1);
                        if (key.EndsWith("\"")) key = key.Substring(0, key.Length - 1);
                        result.Add(int.Parse(key), int.Parse(value));
                    }
    
                    return result;
                }
    
                return base.ConvertStringToValue(parameter, parameterType);
            }
        }
        class MyWebHttpBehavior : WebHttpBehavior
        {
            protected override QueryStringConverter GetQueryStringConverter(OperationDescription operationDescription)
            {
                return new MyQueryStringConverter();
            }
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            host.AddServiceEndpoint(typeof(Service), new WebHttpBinding(), "").Behaviors.Add(new MyWebHttpBehavior());
            host.Open();
            Console.WriteLine("Host opened");
    
            WebClient c = new WebClient();
            Console.WriteLine(c.DownloadString(baseAddress + "/CollabSortFolder?FolderId=12&Items={\"1\":3,\"4\":5,\"6\":7}"));
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method like this: [WebGet(UriTemplate = /)] [OperationContract] public XmlElement All() {}
I have method which return the latitude of the location public double[] getlat(){ double
How can I define a [OperationContract] [WebGet] method to return XML that is stored
I have method that as follows public int TranslateOOV(string word, Stream logStream) { StreamWriter
I have a WCF data service [WebGet] method returning an int. (no of products
I have a method which takes params object[] such as: void Foo(params object[] items)
I have a method that can return either a single object or a collection
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
I have this certain method(snippet below) for which I want to get the XML
My current WCF REST Method is defined as: [OperationContract] [WebGet(UriTemplate = {username}/{password}, ResponseFormat =

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.