WCF 客户端调用服务操作的两种方法
本节的主要内容:1、通过代理类的方式调用服务操作。2、通过通道的方式调用服务操作。3、代码下载
一、通过代理类的方式调用服务操作(两种方式添加代理类)
1.手动编写代理类,如下:
客户端契约:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 using System.ServiceModel; 7 namespace y.WcfFirst.Client.Proxys 8 { 9 [ServiceContract] 10 public interface IHello 11 { 12 [OperationContract] 13 string Say(string name); 14 } 15 }
客户端代理类:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 using System.ServiceModel; 7 using System.ServiceModel.Channels; 8 namespace y.WcfFirst.Client.Proxys 9 { 10 public class HelloProxy:ClientBase<IHello>,IHello 11 { 12 public HelloProxy() 13 : base() 14 { 15 } 16 17 public string Say(string name) 18 { 19 return base.Channel.Say(name); 20 } 21 } 22 }