3

I have developed one REST service using servicestack and in ServiceModel i have created perfmon class, as per my criteria posted on this link Dynamically select property in Linq query , i have used dictionary in perfmon class, Now Get methods work very well but could not able to make post request

public class Perfmon
    {

        public long id { get; set; }

        private readonly Dictionary<string, string> _counters = new Dictionary<string, string>();

        public Perfmon(params KeyValuePair<string, string>[] knownCounters)
        {
            foreach (var knownCounter in knownCounters)
            {
                SetCounter(knownCounter.Key, knownCounter.Value);
            }
        }
        public void SetCounter(string name, string value)
        {
            _counters[name] = value;
        }

        protected string GetCounterValue(string name)
        {
            if (_counters.ContainsKey(name))
                return _counters[name];
            else
                return null;
        }   

        public string counter1{ get { return GetCounterValue("counter1"); } set { SetCounter("counter1", value); } }

  .....
  .....
  .....
    }

so it is sure that because of this i could not able to make post request , because when transfer all counters with like public string counter1 { get; set; } then it worked well. What should i do to resolve this situation , should i avoid to use dictionary??

thanks in advance.

Community
  • 1
  • 1
Arun Rana
  • 8,426
  • 14
  • 67
  • 107
  • BTW you shouldn't address Q's to specific people i.e. rem mythz ref :) What class is this? is this meant to be a DTO? because DTO's shouldn't contain behavior only data. – mythz Nov 09 '11 at 16:58

1 Answers1

0

If this is a DTO then you need to make sure that you always add a parameter-less constructor, so the deserializer can re-create your class e.g:

public class Perfmon
{
    public Perfmon() {}
    ....
}
mythz
  • 141,670
  • 29
  • 246
  • 390