Do you use enum types in your WCF web services?

前端 未结 9 2002
臣服心动
臣服心动 2020-11-27 06:06

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 som

9条回答
  •  执笔经年
    2020-11-27 06:17

    Enums in WSDLs must be considered as a concern for maintenance.

    Adding or removing an enumeration value is(should be!) a trigger for a major update of the interface. If the enum is an output value, then you necessarily need to define a new version of the WSDL through a new URI, so to keep current clients from breaking the established contract("what if they receive on of these new, unexpected values in return?") If the enum is an input value, you could consider this as a minor update("since current clients won't need to know about this new value"), but then, the only way for those clients to benefit from the addition of this new option/functionnality (you added this new enum value for a reason, right?) would be to ask them to switch, later or sooner, to the new version of the interface.

    And this doesn't have to do with the functionnal meaning of the enum, I think.

    Stay on the best practices side, and you'll be safe.

提交回复
热议问题