winform调用WCF默认实例

一:截图

winform调用WCF默认实例winform调用WCF默认实例

二:调用代码

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
    }
}

 

winform调用WCF默认实例

上一篇:ASP.NET 5系列教程 (六): 在 MVC6 中创建 Web API


下一篇:Spark API编程动手实战-07-join操作深入实战