Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd recommend <strong>not</strong> sending enums over WCF interfaces. Suppose you have the following enum:</p> <pre><code>[DataContract] public enum WeekdayEnum { [EnumMember] Monday = 0 } </code></pre> <p>If you return the enum over WCF, everything will work well:</p> <pre><code>[ServiceContract] public class Service1 { [OperationContract] public List&lt;WeekdayEnum&gt; GetWeekdays() { return new List&lt;WeekdayEnum&gt; { WeekdayEnum.Monday }; } } </code></pre> <p>Add to the enum without updating the Service Reference in the client and you're still fine:</p> <pre><code>[DataContract] public enum WeekdayEnum { [EnumMember] Monday = 0, [EnumMember] Tuesday = 1 } </code></pre> <p>However, if you return the added value from the service without updating the client Service References, <strong>the legacy clients will break</strong>:</p> <pre><code>[ServiceContract] public class Service1 { [OperationContract] public List&lt;WeekdayEnum&gt; GetWeekdays() { // NetDispatcherFaultException on legacy clients that only have Monday return new List&lt;WeekdayEnum&gt; { WeekdayEnum.Monday, WeekdayEnum.Tuesday }; } } </code></pre> <p>I've had issues with this in projects where supporting legacy clients is important. The solution has been to simply send DTOs over the WCF instead of enums. E.g. the WeekdayEnum could be replaced by sending the values over a simple DTO:</p> <pre><code>[DataContract] public class WeekdayDto { [DataMember] public int Id { get; set; } [DataMember] public string Name { get; set; } } </code></pre> <p>This way, your legacy clients stay happy.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload