static void Main(string[] args) { Console.WriteLine("调用 WCF 服务开始!"); using (MyWcfServiceClient service = new MyWcfServiceClient("BasicHttpBinding_IMyWcfService")) { Console.WriteLine("调用 service.GetData(100), 返回:" + service.GetData(100)); CompositeType ct = new CompositeType() { StringValue = "Test", BoolValue = true }; Console.WriteLine("调用前 ct: BoolValue={0}; StringValue={1}", ct.BoolValue, ct.StringValue); Console.WriteLine("调用 service.GetDataUsingDataContract(ct)"); ct = service.GetDataUsingDataContract(ct); Console.WriteLine("调用后 ct: BoolValue={0}; StringValue={1}", ct.BoolValue, ct.StringValue); } Console.WriteLine("调用 WCF 服务结束!"); Console.ReadLine(); }
public CompositeType GetDataUsingDataContract(CompositeType composite) { if (composite.BoolValue) { composite.StringValue += "Suffix"; } return composite; }
/// <summary> /// 实现 WCF 服务接口 的代码. /// </summary> /// <param name="composite"></param> /// <returns></returns> public CompositeType GetDataUsingDataContract(CompositeType composite) { if (composite == null) { throw new ArgumentNullException("composite"); } if (composite.BoolValue) { composite.StringValue += "Suffix"; } return composite; }