Enum is not welcome in WCF RRS feed

  • Question

  • It's a strange topic because enum originally supports WCF. However, a good service should support rolling upgrade which means service can be calld by a low version client. Here, enum is not welcome.

    For example, the server transfers enum People{Teacher, Student}, however low version client only supports enum People {Teacher} without Student element. There is one error in deserialization. 

    Any idea about enum in service which needs support rolling upgrade?

    Saturday, May 4, 2013 12:44 PM


  • Hi,

    Of course we can use the enum in WCF services.

    Here is a article about how to use the enum in WCF services. .

    But 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.

    Hope it can help you.

    Best Regards.

    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 7, 2013 7:33 AM