Making Backward-Compatible WCF Services

此生再无相见时 提交于 2019-12-05 02:39:19

WCF is backwards-compatible by default.

The following MSDN link contains a list of all the possible changes of a WCF contract and describes their effect on old clients:

Most importantly, the following operations will not cause old clients to break:

Service contracts (methods)

  • Adding method parameters: The default value will be used when called from old clients.
  • Removing methods parameters: The values sent by old clients will be ignored silently.
  • Adding new methods: Obviously, old clients won't call them, since they don't know them.

Data contracts (custom classes for passing data)

  • Adding non-required properties.
  • Removing non-required properties.

Thus, unless you mark the new DownloadLink field as IsRequired (default is false), your change should be fine.

If you look at this article http://blogs.msdn.com/b/craigmcmurtry/archive/2006/07/23/676104.aspx

The first example the guy gives will satisfy your requirements. It has the benefit that existing clients will not break, and you can add as many new service operations as you want this way.

[ServiceContract] 
public interface IMyServiceContract 
{    
    [OperationContract(IsOneWay=true)]    
    public void MyMethod(MyDataContract input); 
}

[ServiceContract] 
public interface IMyAugmentedServiceContract: IMyServiceContract 
{    
    [OperationContract(IsOneWay=true)]    
    public void MyNewMethod(MyOtherDataContract input); 
}  

The change your service implementation:

public class MyOriginalServiceType: IAugmentedServiceContract { }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!