一:截图
二:调用代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WCFwinformTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); comboBox1.SelectedIndex = 0; } #region 方法一 private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Trim().Length > 0) { WinformServiceReference.Service1Client winformSC = new WinformServiceReference.Service1Client(); int i = Convert.ToInt32(textBox1.Text.Trim()); MessageBox.Show(winformSC.GetData(i)); } } #endregion #region 方法二 private void button2_Click(object sender, EventArgs e) { if (textBox2.Text.Trim().Length > 0) { WinformServiceReference.Service1Client WinformSC = new WinformServiceReference.Service1Client(); WinformServiceReference.CompositeType ct = new WinformServiceReference.CompositeType(); ct.BoolValue = Convert.ToBoolean(comboBox1.Text); ct.StringValue = textBox2.Text; WinformServiceReference.CompositeType newCT = new WinformServiceReference.CompositeType(); newCT = WinformSC.GetDataUsingDataContract(ct); MessageBox.Show(newCT.StringValue); } } #endregion } }