Do you use enum types in your WCF web services?

I've heard some people saying that enums are evil and shouldn't be used in web services because of the mismatches that could occur between the server and the client if some values are assigned, or if the enum is marked with the Flags attribute. They also said that web services exposing enums are harder to maintain but couldn't really give me viable arguments. So from your experience what are the pros and cons of using enums in a WCF web service?


The reason people recommend to avoid enums in webservices is because they create subtle backwards compatible problems.

The same applies to regular enums but in web services the problem is even more clear specially in .NET-generated proxies (see below).

  • If the enumerate is input only you have no issues.
  • If the enumerate can be an out parameter then if you add a new element and you return it, old clients could have problems:
    • If the client is using a .NET-generated proxy it will break before the caller can handle it (in the deserialization)
    • Even if the generated code for the proxy supported the change (for example if it maps the enumerate to a string) the user code in the client may not process properly the new unexpected value (it could easily be a never executed path)

By defining the parameter as a string you signal the user of your API that the value may change in the future. Even if you think that the value will never change is a good practice to be ready.

There is a good post by Dare Obasanjo on this topic.

Need Your Help

How to import a .dmp file (Oracle) into MySql DB?

mysql import export clob

The .dmp is a dump of a table built in Oracle 10g (Express Edition) and one of the fields is of CLOB type.

VBA: Function to remove all special characters

excel vba excel-vba

I've done some searching for a solution to this and I've not been able to find something I can use directly. Therefore, by trying to edit someone else's code for my own use, I've come to an issue....