I have a WebMethod on an ASP.NET webservice which is returning an array of an Enum. If a new value is added, and that value is returned by a function call, then a consumer of the webservice will throw an exception, even though it doesn't care about that enum value.
[WebMethod]
public UserRole[] GetRoles(string token)
partial wsdl:
<s:simpleType name="UserRole">
<s:restriction base="s:string">
<s:enumeration value="Debug" />
<s:enumeration value="EventEditor" />
<s:enumeration value="InvoiceEntry" />
</s:restriction>
</s:simpleType>
(Consumer is compiled with this wsdl, but then wsdl changes and a new value is now allowed - if that value is returned, an XML exception is thrown by the client.)
Is there any way to override SOAP deserialization for this type so that I can catch the error and either remove that item from the array or replace it with a default value? If this was using JSON instead of XML, I could register a JsonConverter to handle that type, so I guess I'm looking for a similar global "RegisterConverter" type function. Which I don't think exists, but hoping for some help...
Any means of decorating the Enum with Attributes will not work, because all the code is generated by the wsdl and is regenerated when the web reference is updated. Normally if I want to modify a class that was generated by a wsdl, I can create a partial class, but that doesn't work for an Enum. And not even sure if I could override the XmlSerialization code even if it was a class.
Some additional background:
This is actually implemented as my attempt at a dynamic Enum. The wsdl is generated from a database lookup so that I can add extra values to the database and the consuming application will have access to the allowed values without having to recompile the webservice. This way I get intellisense and constraint enforcement via the enum type, but the ability to add values without tightly coupling the webservice code and the client code. The problem is that if I add a new value, it creates the potential to break consumers that aren't updated with the new wsdl... I would much rather just ignore that value, since the consumers wouldn't know what to do with it anyway.
A SOAP Extension might be the way to fix this (I know how to add a SOAP Extension to the WebService itself, but have no idea how to add one on the client side...), but it's not ideal because I'd really like to have a generic way of handling this easily so I can have more dynamic enums in my code (they're not really dynamic, but the idea is that the values pass through the middle layer of the webservice without having to recompile that middle layer). Something like "XmlSerialization.RegisterConverter(MyDynamicEnumType, DynamicEnum.Convert)" would be ideal, where I can define a generic function to use and register.)