WCF Basic(1)-操作重载
生活随笔
收集整理的這篇文章主要介紹了
WCF Basic(1)-操作重载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
???? 現網上關于WCF所謂是很多,但好書很少.Programming WCF Services 應該算是一本非常好的書。結合書和代碼總結一下.
一.服務器端操作重載
1.接口本身支持重載
interface ICalculator{int Add(int arg1, int arg2);double Add(double arg1, double arg2);}
2.若將此接口作為服務契約,WSDL規定方法不可重載
以下定義是錯誤的
3.可以用OperationContract的Name屬性設置方法的別名
[ServiceContract]interface ICalculator{[OperationContract(Name = "AddInt")]int Add(int arg1, int arg2);[OperationContract(Name = "AddDouble")]double Add(double arg1, double arg2);}
這樣客戶端就會生成AddInt和AddDouble方法.客戶端會生成如下代碼
[ServiceContract]interface ICalculator{[OperationContract]int AddInt(int arg1, int arg2);[OperationContract]double AddDouble(double arg1, double arg2);}class CalculatorClient : ClientBase<ICalculator>, ICalculator{public int AddInt(int arg1, int arg2){return Channel.AddInt(arg1, arg2);}public double AddDouble(double arg1, double arg2){return Channel.AddDouble(arg1, arg2);}//Rest of the proxy}
最好是避免這種寫法,直接修改方法名
二.客戶端操作重載
也可以在客戶端指定別名
[ServiceContract]interface ICalculator{[OperationContract(Name = "AddInt")]int Add(int arg1, int arg2);[OperationContract(Name = "AddDouble")]double Add(double arg1, double arg2);}class CalculatorClient : ClientBase<ICalculator>, ICalculator{public int Add(int arg1, int arg2){return Channel.Add(arg1, arg2);}public double Add(double arg1, double arg2){return Channel.Add(arg1, arg2);}//Rest of the proxy}轉載于:https://www.cnblogs.com/Clingingboy/archive/2010/08/26/1809589.html
總結
以上是生活随笔為你收集整理的WCF Basic(1)-操作重载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: zbb20180710 maven Fa
- 下一篇: Windbg是一款非常好用的经典wind