Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1199
  • Last Modified:

How to Expose Enums using WCF service

Hello,

I have a requirement that i need to expose my enums usign WCF service, Can any one provide me with the link.How to expose Enums using WCF service and how to consume them in at the client end..........



I have exposed enum in the below mentioned format, but when i am trying to acess the same at the client end i am not getting enum name in the intellisense..........

Code: Way i created enum in WCF project

[DataContract( Name = "QuestionType1")]
    public enum QuestionType
    {
        [EnumMember]
        MultipleChoice_OnlyOneAnswer = 1,
        [EnumMember]
        MultipleChoice_MultipleAnswer = 2,
        [EnumMember]
        CommentOrEssayBOx = 3,
        [EnumMember]
        MatrixOfChoice_OnlyOneAnswerPerRow = 4,
        [EnumMember]
        MatrixOfChoice_MultipleAnswerPerRow = 5,
        [EnumMember]
        DropDownMenu = 6,
        [EnumMember]
        SingleTextBox = 7,
        [EnumMember]
        DescriptiveText = 9,
        [EnumMember]
        DemographicInformation_US = 10,
        [EnumMember]
        DemographicInformation_International = 11,
        [EnumMember]
        DateorTime = 12,
        [EnumMember]
        Email = 13,
        [EnumMember]
        HelpText = 14,
        [EnumMember]
        MultipleTextBox = 15,
        [EnumMember]
        PhoneNumber = 16,
        [EnumMember]
        NumberDropDownMenu = 17
    }


I am not able to find QuestionType1 when i am trying to consume this service...............




0
Praveen_Bobbili
Asked:
Praveen_Bobbili
  • 2
2 Solutions
 
sonawanekiranCommented:
Not sure but QuestionType enum should be used in one of data contract for instance

[DataContract]
public enum UserDetails
{
   [DataMember]
   public string name;

    [DataMember]
   public QuestionType enum_test;

}
0
 
gopaltaydeCommented:
Generally DataContracts are kept in a seperate projects and it's reference is added in wcf service project and client project. This way we can access the data contracts.
The another way is suggested by sonawanekiran. The example is available at http://beyondrelational.com/blogs/dhananjaykumar/archive/2011/03/18/enumeration-in-datacontract-of-wcf.aspx
0
 
Praveen_BobbiliAuthor Commented:
Hello,

Reason for the issue i have not decorated my Contract with ServiceKnownType attribute.

If i decorate my interface in the below format i am able to access Enum at my client end.........

 [ServiceKnownType(typeof(QuestionType))]
 public interface ISurveyOperations
{

}  
0
 
Praveen_BobbiliAuthor Commented:
The comments given by the team not helped me in getting the solutions are even it not helped me work towards the solution.   When ever i have discussed this issue with my other team members i have got the solution...............
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now