简体   繁体   English

wcf版本以实现向后兼容

[英]version wcf for backward compatibility

I have a service which has a following method: 我有一种具有以下方法的服务:

[ServiceContract]
public interface TestContract
{
  [OperationContract]
  void GetTest(Test test);
}

Now in my new service contract Type Test has been moved to different namespace with new name TestNew This is my new service contract: 现在,在我的新服务合同中,类型Test已使用新名称TestNew移到了不同​​的名称空间,这是我的新服务合同:

 public interface TestContract
{
  [OperationContract]
  void GetTest(TestNew test);
}

How do I implement the service without breaking the existing client. 如何在不破坏现有客户端的情况下实现服务。 That means achieve backward compatibility without having the existing clients update their service references. 这意味着在不让现有客户端更新其服务引用的情况下实现向后兼容性。

Basically, the type of the parameter changed, which is a breaking change. 基本上,参数的类型已更改,这是一个重大更改。 Since, I have both old and new client now. 从那时起,我现在有了新老客户。 Is there any way I could change my service contract without having to change the service reference of both old and new client? 有什么方法可以更改我的服务合同而无需更改新老客户的服务参考? I was thinking intercepting somewhere during the serialization/deserialization of parameter 我正在考虑在参数的序列化/反序列化期间截取某处

You could define TestNow as a subclass (and KnownType of Test ) and not change the method signature, or you can add a new Action by either changing the name of the method (leaving the old) or using the Name property on the OperationContract attribute. 您可以将TestNow定义为子类(和Test KnownType ),而不更改方法签名,或者可以通过更改方法名称(保留旧方法)或在OperationContract属性上使用Name属性来添加新的Action

The more common approach for a breaking change is to just define a new endpoint. 进行重大更改的更常见方法是仅定义一个新端点。 Eg: http://foo/someservice/2014-05 for the first version and http://foo/someservice/2015-10 for the new one. 例如:第一个版本为http:// foo / someservice / 2014-05 ,新版本为http:// foo / someservice / 2015-10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM