版本控制和落后的可比性 [英] Wcf versioning and backward compatilibilty

查看:70
本文介绍了版本控制和落后的可比性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我必须进行WCF版本控制,还需要向后兼容。

我正在使用频道工厂创建服务实例。



提前致谢,

Pushkar



我尝试了什么:



我试图创建服务合同的版本,但由于我正在使用渠道工厂来创建WCF服务的实例。



Hi all,

I have to do WCF versioning and also it needs to be backward compatible.
I am using channel factory to create instance of service.

Thanks in advance,
Pushkar

What I have tried:

I tried to create versions of service contract but did not work out as i am using channel factory to create instance of WCF service.

[ServiceContract(Name = "Test", Namespace = "http://Test/ServiceContract/2016/1")]
public interface IMYWCFV1
{
     [OperationContract]
     string GetMessage(int id);
        
     [OperationContract]
     int GetId(string message);
        
}

[ServiceContract(Name = "Test", Namespace = "http://Test/ServiceContract/2016/2")]
public interface IMYWCFV2
{
    [OperationContract]
    string GetMessage(int id);
        
    [OperationContract]
    int GetId(string message);
       
}

推荐答案

我建​​议你先阅读 [ ^ ](再次)



创建一个新命名空间中的新服务合同就是这样 - 一个新的服务合同......



所以忘记这一点并从一个新思维开始。问问自己:我想要严格的版本控制吗? (阅读MSDN文章)或松散的版本执行工作? (对于我多年来所有的病例,这是100%真实的)。你最好自己阅读并询问你可能不理解的细节。但是一些一般性的建议 - 永远不要从现有的服务合同中删除任何东西如果消息合同可能会发生变化(如果您只是将它们用作DTO,则不太可能),请改用接口,并以与服务合同相同的方式将消息合同与实现分离。



如果您想要严格的版本控制,如果您有新的严格版本则必须更改客户端,对于松散版本控制,只要新合同是兼容,您就不能更改客户端(=没有删除任何东西,只需添加。)如果你想要使用例如客户端新合同中的新服务方法无论如何都要改变客户......
I'd suggest you start by reading [^] (again)

Creating a new Service contract in a new namespace is just that - a new Service contract...

So forget about this and start with a "fresh mind". Ask yourself: Do I want strict versioning? (read MSDN article) or does lax versioning do the job? (was 100% true for all cases I had over the years). Better you read for yourself and ask for specifics you may don't understand. But some general advice - never remove anything from existing Service contracts, just add. And if message-contracts may change (unlikely if you just use them as DTO's), use interfaces instead and decouple the message contracts from implementation in the same way you'd do with Service contracts.

If you want strict versioning you have to change the clients if you have a new "strict" version, for "lax" versioning you may not change the clients as long as the new contract is "compatible" (=didn't remove anything, just add.) If you then want to use e.g. a new service method from the newer contract on client-side you have to change the clients anyway...


这篇关于版本控制和落后的可比性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆