WCF - 版本问题
发布日期:2021-06-29 03:54:10
浏览次数:2
分类:技术文章
本文共 2206 字,大约阅读时间需要 7 分钟。
在前面的文章中,我们曾试过用继承的方式来实现版本更新。如果我们直接修改原有服务和数据类型会怎么样呢?
测试原型: [DataContract] public class Data { [DataMember] public int x; } [ServiceContract] public interface IMyService { [OperationContract] void Test(Data d); }
客户端代理 //------------------------------------------------------------------------------ // <auto-generated> // 此代码由工具生成。 // 运行库版本:2.0.50727.42 // // 对此文件的更改可能会导致不正确的行为,并且如果 // 重新生成代码,这些更改将会丢失。 // </auto-generated> //------------------------------------------------------------------------------ namespace ConsoleApplication1.localhost { [GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")] [DataContractAttribute(Namespace = "...")] [SerializableAttribute()] public partial class Data : object, IExtensibleDataObject { [OptionalFieldAttribute()] private int xField; [DataMemberAttribute()] public int x { get { return this.xField; } set { this.xField = value; } } } [GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] [ServiceContractAttribute(ConfigurationName = "ConsoleApplication1.localhost.IMyService")] public interface IMyService { [OperationContractAttribute(Action = "http://tempuri.org/IMyService/Test", ReplyAction = "...")] void Test(Data d); } [GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] public interface IMyServiceChannel : IMyService, IClientChannel { } [DebuggerStepThroughAttribute()] [GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] public partial class MyServiceClient : ClientBase<IMyService>, IMyService { public void Test(Data d) { base.Channel.Test(d); } } }
我们将对该服务和数据类型进行升级,添加新的成员和服务方法。 [DataContract] public class Data { [DataMember] public int x; [DataMember] public int y; } [ServiceContract] public interface IMyService { [OperationContract] void Test(Data d); [OperationContract] void Test2(int x); }
测试结果表明,客户端在不更新代理文件的情况下依然正常执行。看来直接通过修改进行版本更新也没有什么问题。要是我们修改了成员的名称会怎么样?也没问题,不过要使用 Name 属性了。 [DataContract] public class Data { [DataMember(Name="x")] public int x2; [DataMember] public int y; } [ServiceContract] public interface IMyService { [OperationContract] void Test(Data d); [OperationContract] void Test2(int x); }
提示:1. 最好为服务和相关成员特性添加 Namespace / Name 属性。(不要受我的演示代码影响…… )2. 还是使用继承方式进行版本更新要好些,避免因为意味更改造成原有客户端无法执行。 转载地址:https://blog.csdn.net/zengjibing/article/details/3812409 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月22日 10时21分54秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Atiitt attilax掌握的前后技术放在简历里面.docx
2019-04-29
Atiitt 文档处理之道 attilax著
2019-04-29
Atiitt 可视化 报表 图表之道 attilax著 Atitit.可视化与报表原理与概论 1. 信息可视化 1 2. Gui可视化 2 2.1. atitit 知识的可视化.docx 2
2019-04-29
paip.c#图片裁剪
2019-04-29
paip.html 及css调试工具---debugbar
2019-04-29
paip.项目开发效率提升之思索
2019-04-29
paip.项目开发效率提升之思索
2019-04-29
Atitit spring5 集成 mybatis 注解班
2019-04-29
Atitit springboot mybatis spring 集成 Springboot1.4 mybatis3.4.6 /springbootMybatis 目录 1.1. 设置map
2019-04-29
Atitit 模板引擎总结 目录 1. 模板引擎 1 2. 常见模板步骤 1 2.1. 1)定义模板字符串 1 2.2. 2)预编译模板 2 2.3. 渲染模板 2 3. 流程渲染 if el
2019-04-29
Atitit 字符串转换数组main参数解析 args splitByWholeSeparator String string=" -host 101.1 8*124 -db 1
2019-04-29
paip.提升效率----几款任务栏软件vc59
2019-04-29
paip.验证码识别---序列号的反转
2019-04-29
paip.php调试脱离IDE VC59
2019-04-29
paip.DEVSUIT WEB .NET ASPX网站打开慢的原因
2019-04-29
央行数字货币将取代纸币?这篇文章说明白了
2019-04-29
2020消费金融大变局:科技向下扎根 持牌向上生长
2019-04-29
高质量壁纸网站,满足壁纸控的所有想象!
2019-04-29
游戏英雄联盟高清壁纸,人物角色都包括
2019-04-29
吃货注意接收,精美美食图片壁纸来喽
2019-04-29