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

創(chuàng)新互聯(lián)建站于2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元臥龍做網(wǎng)站,已為上家服務(wù),為臥龍各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
WCF版本更新測(cè)試原型:
- [DataContract]
- public class Data
- {
- [DataMember]
- public int x;
- }
- [ServiceContract]
- public interface IMyService
- {
- [OperationContract]
- void Test(Data d);
- }
客戶端代理
- //------------------------------------------
- // < auto-generated>
- // 此代碼由工具生成。
- // 運(yùn)行庫版本:2.0.50727.42
- //
- // 對(duì)此文件的更改可能會(huì)導(dǎo)致不正確的行為,并且如果
- // 重新生成代碼,這些更改將會(huì)丟失。
- // < /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);
- }
- }
- }
我們將對(duì)該服務(wù)和數(shù)據(jù)類型進(jìn)行升級(jí),添加新的成員和服務(wù)方法來實(shí)現(xiàn)WCF版本更新。
- [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);
- }
測(cè)試結(jié)果表明,客戶端在不更新代理文件的情況下依然正常執(zhí)行??磥碇苯油ㄟ^修改進(jìn)行版本更新也沒有什么問題。要是我們修改了成員的名稱會(huì)怎么樣?也沒問題,不過要使用 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);
- }
WCF版本更新的操作提示:
1. ***為服務(wù)和相關(guān)成員特性添加 Namespace / Name 屬性。
2. 還是使用繼承方式進(jìn)行版本更新要好些,避免因?yàn)橐馕陡脑斐稍锌蛻舳藷o法執(zhí)行。
分享文章:WCF版本更新應(yīng)用直接修改方法實(shí)現(xiàn)
分享路徑:http://www.dlmjj.cn/article/djieehd.html


咨詢
建站咨詢
