自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

WCF版本更新應(yīng)用直接修改方法實(shí)現(xiàn)

開發(fā) 開發(fā)工具
我們將會在接下來的這篇文章中為大家詳細(xì)介紹一下有關(guān)WCF版本更新的不同實(shí)現(xiàn)方式,希望大家可以從中獲得一些幫助。

大多數(shù)開發(fā)人員在使用WCF進(jìn)行版本更新時(shí),大部分都會通過繼承的方式來實(shí)現(xiàn)。那么,還有沒有其他更加簡便的方式呢?下面我們就為大家介紹一種直接修改原有服務(wù)和數(shù)據(jù)類型的方法來實(shí)現(xiàn)WCF版本更新。

WCF版本更新測試原型:

  1. [DataContract]  
  2. public class Data  
  3. {  
  4. [DataMember]  
  5. public int x;  
  6. }  
  7. [ServiceContract]  
  8. public interface IMyService  
  9. {  
  10. [OperationContract]  
  11. void Test(Data d);  

客戶端代理

  1. //------------------------------------------  
  2. // < auto-generated> 
  3. // 此代碼由工具生成。  
  4. // 運(yùn)行庫版本:2.0.50727.42  
  5. //  
  6. // 對此文件的更改可能會導(dǎo)致不正確的行為,并且如果  
  7. // 重新生成代碼,這些更改將會丟失。  
  8. // < /auto-generated> 
  9. //-------------------------------------------  
  10. namespace ConsoleApplication1.localhost  
  11. {  
  12. [GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]  
  13. [DataContractAttribute(Namespace = "...")]  
  14. [SerializableAttribute()]  
  15. public partial class Data : object, IExtensibleDataObject  
  16. {  
  17. [OptionalFieldAttribute()]  
  18. private int xField;  
  19. [DataMemberAttribute()]  
  20. public int x  
  21. {  
  22. get  
  23. {  
  24. return this.xField;  
  25. }  
  26. set  
  27. {  
  28. this.xField = value;  
  29. }  
  30. }  
  31. }  
  32. [GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]  
  33. [ServiceContractAttribute(ConfigurationName = 
    "ConsoleApplication1.localhost.IMyService")]  
  34. public interface IMyService  
  35. {  
  36. [OperationContractAttribute(Action = "http://tempuri.org/IMyService/Test", 
    ReplyAction = "...")]  
  37. void Test(Data d);  
  38. }  
  39. [GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]  
  40. public interface IMyServiceChannel : IMyService, IClientChannel  
  41. {  
  42. }  
  43. [DebuggerStepThroughAttribute()]  
  44. [GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]  
  45. public partial class MyServiceClient : ClientBase< IMyService>, 
    IMyService  
  46. {  
  47. public void Test(Data d)  
  48. {  
  49. base.Channel.Test(d);  
  50. }  
  51. }  

我們將對該服務(wù)和數(shù)據(jù)類型進(jìn)行升級,添加新的成員和服務(wù)方法來實(shí)現(xiàn)WCF版本更新。

  1. [DataContract]  
  2. public class Data  
  3. {  
  4. [DataMember]  
  5. public int x;  
  6. [DataMember]  
  7. public int y;  
  8. }  
  9. [ServiceContract]  
  10. public interface IMyService  
  11. {  
  12. [OperationContract]  
  13. void Test(Data d);  
  14. [OperationContract]  
  15. void Test2(int x);  

測試結(jié)果表明,客戶端在不更新代理文件的情況下依然正常執(zhí)行??磥碇苯油ㄟ^修改進(jìn)行版本更新也沒有什么問題。要是我們修改了成員的名稱會怎么樣?也沒問題,不過要使用 Name 屬性了。

  1. [DataContract]  
  2. public class Data  
  3. {  
  4. [DataMember(Name="x")]  
  5. public int x2;  
  6. [DataMember]  
  7. public int y;  
  8. }  
  9. [ServiceContract]  
  10. public interface IMyService  
  11. {  
  12. [OperationContract]  
  13. void Test(Data d);  
  14. [OperationContract]  
  15. void Test2(int x);  

WCF版本更新的操作提示:

1. ***為服務(wù)和相關(guān)成員特性添加 Namespace / Name 屬性。

2. 還是使用繼承方式進(jìn)行版本更新要好些,避免因?yàn)橐馕陡脑斐稍锌蛻舳藷o法執(zhí)行。

【編輯推薦】

  1. WCF枚舉類型正確使用方法演示
  2. WCF服務(wù)實(shí)例管理模式之PreSession應(yīng)用
  3. WCF控制服務(wù)對象釋放特殊方式介紹
  4. 深入分析WCF事務(wù)投票實(shí)現(xiàn)方式
  5. WCF MSMQ隊(duì)列基本概念簡述
責(zé)任編輯:曹凱 來源: 豆豆網(wǎng)
相關(guān)推薦

2009-12-22 16:36:38

WCF重載

2009-12-22 17:30:47

WCF Address

2009-12-21 16:04:45

WCF Dispose

2010-02-22 11:02:06

WCF元數(shù)據(jù)

2009-12-21 17:48:30

WCF方法重載

2010-02-22 14:28:35

WCF實(shí)現(xiàn)loadin

2009-12-21 17:40:25

WCF會話

2010-03-02 17:35:20

WCF服務(wù)加載

2010-02-24 09:38:58

WCF應(yīng)用編碼

2010-02-26 16:05:14

寄宿WCF服務(wù)

2010-02-24 11:22:04

WCF方法重載

2009-12-21 17:24:46

WCF負(fù)載平衡

2010-02-23 14:48:38

WCF事件通知

2009-12-21 18:10:50

WCF實(shí)現(xiàn)事件通知

2010-02-26 11:22:16

LitwareHR使用

2010-02-25 09:58:05

WCF配置指定Addr

2012-06-12 16:45:57

PHP

2010-02-25 13:48:23

WCF動態(tài)創(chuàng)建代碼

2010-02-25 16:52:12

引用WCF服務(wù)

2010-02-24 16:39:27

WCF客戶端處理
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號