使用枚举的 WCF 前向兼容性
我读过这篇关于版本之间枚举更改的帖子,但这对我没有帮助。 我有以下 wcf 服务:
[ServiceContract]
public interface IService1
{
[OperationContract]
MyEnum Foo();
}
[DataContract]
public enum MyEnum
{
[EnumMember]
first,
[EnumMember]
Second,
}
我正在寻找一种添加新枚举成员的方法,仅添加到服务端。假设我的客户端正在使用旧版本的代理,没有我想要添加的新枚举成员。 我的目标是避免序列化异常,我希望我的客户端足够聪明来处理这种情况,忽略新值或任何东西。有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您链接到的问题的答案,向枚举添加新元素不会破坏兼容性。
将会崩溃的是将枚举值发送到枚举列表中没有该值的客户端。
要通过仅更改服务器端来解决此问题:
这可能比其价值更多的工作,这取决于有多少客户端您已经拥有以及更新它们有多困难。
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:
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.