gpt4 book ai didi

WCF DataContract 版本控制

转载 作者:行者123 更新时间:2023-12-04 18:10:16 26 4
gpt4 key购买 nike

好吧,这里什么都没有。在阅读了服务版本控制和数据契约(Contract)版本控制的最佳实践 (http://msdn.microsoft.com/en-us/library/ms733832.aspx) 之后,我基本上了解了它是如何完成的。我计划对数据契约(Contract)使用敏捷版本控制,但无法弄清楚创建 WorkRequestV2 以添加新属性或仅将新属性添加到 WorkRequestV1 之间有什么区别或更好的做法。现在我尝试了这两种方法并且它有效但是当我创建 WorkRequestV2 时我必须修改 ServiceContractor 以使用 WorkRequestV2 为什么这样做而不是仅仅向 WorkRequestV1 添加属性?有什么区别?

我看过的例子在这里 ( http://msdn.microsoft.com/en-us/library/ms731138.aspx )CarV1 和 CarV2 为什么不将 HorsePower 添加到 CarV1 而不必创建一个全新的合约。

[DataContract(Name = "WorkRequest")]
public class WorkRequestV1 : IExtensibleDataObject {
[DataMember(Name = "workrequest",Order=1,IsRequired=true)]
public int workrequest { get; set; }
[DataMember(Name = "CQ")]
public string CrewHeadquarter { get; set; }
[DataMember(Name = "JobCode")]
public string JobCode { get; set; }
[DataMember(Name = "JobType")]
public string JobType { get; set; }
[DataMember(Name = "Latitude")]
public string Latitude { get; set; }
[DataMember(Name = "Longitute")]
public string Longitute { get; set; }

private ExtensionDataObject theData;
public ExtensionDataObject ExtensionData {
get {
return theData;
}
set {
theData = value;
}
}
}

最佳答案

再读一遍数据契约版本控制(你的第二个链接)

这是该页面的引述:

Breaking vs. Nonbreaking Changes

Changes to a data contract can be breaking or nonbreaking. When a data contract is changed in a nonbreaking way, an application using the older version of the contract can communicate with an application using the newer version, and an application using the newer version of the contract can communicate with an application using the older version. On the other hand, a breaking change prevents communication in one or both directions.

对于您的情况,添加一些额外的属性是一项非破坏性更改。只要您没有严格的架构验证(例如新属性上没有标记“必需”),您就可以非常安全地将属性添加到现有数据协定中,而不是创建一个新协定

与新服务通信的旧客户端仍然继续工作,新属性的值将保持默认值。与旧服务通信的新客户端也可以工作,因为新属性将被忽略。

但如您所见,您会遇到一个问题,即如何确保新客户与新服务通信,以及老客户与旧服务通信?如果这不是问题,那么您就没有问题。否则,您可能需要引入新的数据契约(Contract)。

进一步阅读:

MSDN Service Versioning

IBM Best practice for Web service versioning

Oracle Web services versioning

What are your WebService Versioning best practices?

关于WCF DataContract 版本控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15369585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com