2

I have been looking for hours now and i have no idea how to solve my problem. I am writing a Service Stack API and I need whoever is going to consume it to pass in valid values in only.

I have a Client node and under there is firstname, lastname, address, state, etc.

Now for the state field it needs to be enumerable is some way so they can only choose for example (NT, NSW, WA, SA)

So they will go something like objClient.State = State.NT;

BTW this is in C# asp.net with mono framework.

Now what i have tried is to do a private static readonly string BLABLABLA; but that didn't work, Its not getting serialized. All My DTO's have [DataContract] and [DataMember] tags at the appropriate places. I Tried doing [Flags] above the enum that i tried but no luck.

So i am stuck at the moment. I don't want the consumer of the api to just pass in a string value. can anyone help me get unstuck with some suggestions how to do this?

Shane van Wyk
  • 1,870
  • 1
  • 26
  • 62
  • dont know if this will work tho? http://msdn.microsoft.com/en-us/library/system.runtime.serialization.enummemberattribute.aspx – Shane van Wyk May 05 '13 at 09:16
  • 1
    Check out : http://stackoverflow.com/questions/3570249/using-enums-in-wcf-data-services or http://stackoverflow.com/questions/12154754/passing-enums-via-wcf-service – Saravanan May 05 '13 at 09:54

1 Answers1

1

I solved this using:

[DataContract]
public enum Color
{
    [DataMember]
    Red,
    [DataMember]
    Blue,
    [DataMember]
    Green,
}
Shane van Wyk
  • 1,870
  • 1
  • 26
  • 62