1

I've read this post regarding enumaration changes between versions, but it didn't help me. I have the following wcf service:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    MyEnum Foo();
}

[DataContract]
public enum MyEnum
{
    [EnumMember]
    first,
    [EnumMember]
    Second,
}

I'm looking for a way to add a new enum member, only to the service side. Let's say my client is using an old version of the proxy, without the new enum member I want to add. My goal is avoiding a serialization exception, I want my client to be smart enough to handle this situation, ignoring the new value or anything. Any Ideas?

Community
  • 1
  • 1
Sean
  • 81
  • 1
  • 7

1 Answers1

4

According to the answer in the question that you linked to, adding a new element to the enum does not break compatibility.

What will crash is sending an enum value to a client that does not have that value in the enum list.

To fix this by only changing the server side:

  • Add new value to enum
  • Create new service method that does the same as the old
  • New clients will use the new service
  • The old clients will use the old service
  • In the old service, before the result is sent, check if one of the new enum values are being used, if so change it to one of the old ones ("Uknown" if you have that value)

This may be more work than it is worth, it depends on how many clients you have and how difficult it is to update them.

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
  • Thanks for the quick reply. 1. My problem is I already released the old version, and I don't have an 'unknown' value in my enums, so I can't change the new values to a default value. 2. In the last dot, did you mean this trick should happen in the WCF behaviour or somewhere else? – Sean Feb 05 '12 at 14:20
  • for point 2 it should happen in your code, just before the return statement. for point 1 can you change it to any of the existing values? What are the business rules for what should happen if an old client gets a new enum? – Shiraz Bhaiji Feb 05 '12 at 14:31
  • If an old client gets a new enum, I would have liked to ignore it, or switch it to a default value which I currently don't have. But this solution brings another problem - a new client will not be able to work with an old service, because it'll fail invoking the 'new service' (which doesn't exist in old service). – Sean Feb 05 '12 at 15:24