Data Contracts in Windows Communication Foundation (WCF)

I've been going over data contracts for WCF lately and wanted to post a few specifics. One issue I ran into recently was odd, as it included an enumeration that needed to be included in part of a data contract. I had tagged the enumeration with the [DataContract] attribute but I was receiving an odd issue about the service disconnecting. The error message I was getting was something like this:

I had read, or thought via failed comprehension, that I could just tag an enumeration with [DataContract] as below.

   1:  [DataContract] 
   2:  public enum Priority 
   3:  { 
   4:      Low, 
   5:      Medium, 
   6:      High 
   7:  } 

As it turns out though, the [EnumMember] attribute needs added to the enumeration.

   1:  [DataContract] 
   2:  public enum Priority 
   3:  { 
   4:      [EnumMember] 
   5:      Low, 
   6:      [EnumMember] 
   7:      Medium, 
   8:      [EnumMember] 
   9:      High 
  10:  } 

After I added that, smooth sailing resumed. So don't just tag the enumeration, tag the members too. I'm also working on some other notes from my reintroduction to WCF (I've done a ton of work with it in the past) so stay tuned for that.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted by: Adron
Posted on: 10/24/2008 at 3:33 PM
Tags: , ,
Categories: How-To, Samples, and Such
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

Comments

Comments are closed