Do you use enum types in your WCF web services?

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.

Leave a Comment