C# 中WebService返回类型(string,int,bool,DataSet,class实体类)示例
2008-12-18 10:55
525 查看
WebService 服务可以返回任何可序列化的对象.本文代码给出返回基本数据类型及实体类结构示例和调用代码示例.
WebService代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace StudentServer
{
/// <summary>
/// 本类实现WebService服务
/// 提供对各种数据类型的返回例子
/// 包括:
/// 基本数据类型(string,ini,bool,long,float等)
/// 类结构型(class),必须是可序列化的类
/// DataSet类型
/// </summary>
public class Demo : System.Web.Services.WebService
{
public Demo()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
#region 组件设计器生成的代码
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
// WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键
/// <summary>
/// 字符串型
/// </summary>
/// <returns>Hello World</returns>
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
/// <summary>
/// 整型
/// </summary>
/// <returns>Int</returns>
[WebMethod]
public int GetInt()
{
return 1234;
}
/// <summary>
/// 布尔型
/// </summary>
/// <returns>Bool</returns>
[WebMethod]
public bool GetBool()
{
return true;
}
/// <summary>
/// 返回实体类
/// 必须是已序列化的类
/// </summary>
/// <returns>学生类</returns>
[WebMethod]
public Student GetStudent()
{
Student stu = new Student();
stu.Name = "张三";
stu.Age = 25;
stu.Sex = true;
return stu;
}
/// <summary>
/// 返回DataSet数据类型
/// </summary>
/// <returns>DataSet</returns>
[WebMethod]
public DataSet GetDataSet()
{
DataSet ds = new DataSet();
return ds;
}
}
#region 定义可序列化类
/*
* 为避免Framework1.1中返回实体类报错“请求格式无法识别。”
* 要在Web.Config文件中<system.web>添加以下内容:
* <webServices>
<protocols>
<add name="HttpPost" />
<add name="HttpGet" />
</protocols>
</webServices>
*/
//指示下面的类可序列化
/// <summary>
/// 学生基本信息类
/// </summary>
[Serializable]
public class Student
{
/// <summary>
/// 构造函数
/// </summary>
public Student()
{
}
private string name;
/// <summary>
/// 姓名
/// </summary>
public string Name
{
get
{
return name;
}
set
{
name=value;
}
}
private bool sex;
/// <summary>
/// 性别--布尔型变量真为女,假为男
/// </summary>
public bool Sex
{
get
{
return sex;
}
set
{
sex=value;
}
}
private int age;
/// <summary>
/// 年龄
/// </summary>
public int Age
{
get
{
return age;
}
set
{
age=value;
}
}
}
#endregion
}
调用WebService服务示例代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using StudentClient.localhost;
namespace StudentClient
{
/// <summary>
/// FrmDemo 的摘要说明。
/// </summary>
public class FrmDemo : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button btnStu;
private System.Windows.Forms.Button btnInt;
private System.Windows.Forms.Button btnHello;
private System.Windows.Forms.Button btnDataSet;
private System.Windows.Forms.Button btnBool;
private System.Windows.Forms.TextBox txtSex;
private System.Windows.Forms.TextBox txtAge;
private System.Windows.Forms.TextBox txtOther;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public FrmDemo()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.txtSex = new System.Windows.Forms.TextBox();
this.txtAge = new System.Windows.Forms.TextBox();
this.txtOther = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.btnStu = new System.Windows.Forms.Button();
this.btnInt = new System.Windows.Forms.Button();
this.btnHello = new System.Windows.Forms.Button();
this.btnDataSet = new System.Windows.Forms.Button();
this.btnBool = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 0;
this.label1.Text = "姓名:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(32, 70);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 16);
this.label2.TabIndex = 1;
this.label2.Text = "性别:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(136, 70);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 16);
this.label3.TabIndex = 2;
this.label3.Text = "年龄:";
//
// label4
//
this.label4.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label4.Location = new System.Drawing.Point(72, 8);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(136, 24);
this.label4.TabIndex = 3;
this.label4.Text = "学生基本信息";
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(80, 36);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(144, 21);
this.txtName.TabIndex = 4;
this.txtName.Text = "";
//
// txtSex
//
this.txtSex.Location = new System.Drawing.Point(80, 64);
this.txtSex.Name = "txtSex";
this.txtSex.Size = new System.Drawing.Size(48, 21);
this.txtSex.TabIndex = 5;
this.txtSex.Text = "";
//
// txtAge
//
this.txtAge.Location = new System.Drawing.Point(184, 64);
this.txtAge.Name = "txtAge";
this.txtAge.Size = new System.Drawing.Size(40, 21);
this.txtAge.TabIndex = 6;
this.txtAge.Text = "";
//
// txtOther
//
this.txtOther.Location = new System.Drawing.Point(80, 96);
this.txtOther.Name = "txtOther";
this.txtOther.Size = new System.Drawing.Size(128, 21);
this.txtOther.TabIndex = 7;
this.txtOther.Text = "";
//
// label5
//
this.label5.Location = new System.Drawing.Point(32, 100);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(48, 16);
this.label5.TabIndex = 8;
this.label5.Text = "其它:";
//
// btnStu
//
this.btnStu.Location = new System.Drawing.Point(8, 128);
this.btnStu.Name = "btnStu";
this.btnStu.Size = new System.Drawing.Size(88, 24);
this.btnStu.TabIndex = 9;
this.btnStu.Text = "调用Student";
this.btnStu.Click += new System.EventHandler(this.btnStu_Click);
//
// btnInt
//
this.btnInt.Location = new System.Drawing.Point(200, 128);
this.btnInt.Name = "btnInt";
this.btnInt.Size = new System.Drawing.Size(32, 24);
this.btnInt.TabIndex = 10;
this.btnInt.Text = "Int";
this.btnInt.Click += new System.EventHandler(this.btnInt_Click);
//
// btnHello
//
this.btnHello.Location = new System.Drawing.Point(152, 128);
this.btnHello.Name = "btnHello";
this.btnHello.Size = new System.Drawing.Size(48, 24);
this.btnHello.TabIndex = 11;
this.btnHello.Text = "Hello";
this.btnHello.Click += new System.EventHandler(this.btnHello_Click);
//
// btnDataSet
//
this.btnDataSet.Location = new System.Drawing.Point(96, 128);
this.btnDataSet.Name = "btnDataSet";
this.btnDataSet.Size = new System.Drawing.Size(56, 24);
this.btnDataSet.TabIndex = 12;
this.btnDataSet.Text = "DataSet";
this.btnDataSet.Click += new System.EventHandler(this.btnDataSet_Click);
//
// btnBool
//
this.btnBool.Location = new System.Drawing.Point(232, 128);
this.btnBool.Name = "btnBool";
this.btnBool.Size = new System.Drawing.Size(40, 24);
this.btnBool.TabIndex = 13;
this.btnBool.Text = "Bool";
this.btnBool.Click += new System.EventHandler(this.btnBool_Click);
//
// FrmDemo
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(280, 158);
this.Controls.Add(this.btnBool);
this.Controls.Add(this.btnDataSet);
this.Controls.Add(this.btnHello);
this.Controls.Add(this.btnInt);
this.Controls.Add(this.btnStu);
this.Controls.Add(this.label5);
this.Controls.Add(this.txtOther);
this.Controls.Add(this.txtAge);
this.Controls.Add(this.txtSex);
this.Controls.Add(this.txtName);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FrmDemo";
this.Text = "FrmDemo";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 调用学生信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStu_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
//调用返回实体类服务方法
Student stu = dm.GetStudent();
txtName.Text = stu.Name;
txtSex.Text = (stu.Sex==false?"女":"男");
txtAge.Text = stu.Age.ToString();
}
/// <summary>
/// DataSet数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDataSet_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
txtOther.Text = dm.GetDataSet().Tables.Count.ToString();
}
/// <summary>
/// 返回字符串
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnHello_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
txtOther.Text = dm.HelloWorld();
}
/// <summary>
/// 返回整型
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnInt_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
txtOther.Text = dm.GetInt().ToString();
}
/// <summary>
/// 返回布尔型
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnBool_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
txtOther.Text = dm.GetBool().ToString();
}
}
}
窗体界面如下图:
WebService代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace StudentServer
{
/// <summary>
/// 本类实现WebService服务
/// 提供对各种数据类型的返回例子
/// 包括:
/// 基本数据类型(string,ini,bool,long,float等)
/// 类结构型(class),必须是可序列化的类
/// DataSet类型
/// </summary>
public class Demo : System.Web.Services.WebService
{
public Demo()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
#region 组件设计器生成的代码
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
// WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键
/// <summary>
/// 字符串型
/// </summary>
/// <returns>Hello World</returns>
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
/// <summary>
/// 整型
/// </summary>
/// <returns>Int</returns>
[WebMethod]
public int GetInt()
{
return 1234;
}
/// <summary>
/// 布尔型
/// </summary>
/// <returns>Bool</returns>
[WebMethod]
public bool GetBool()
{
return true;
}
/// <summary>
/// 返回实体类
/// 必须是已序列化的类
/// </summary>
/// <returns>学生类</returns>
[WebMethod]
public Student GetStudent()
{
Student stu = new Student();
stu.Name = "张三";
stu.Age = 25;
stu.Sex = true;
return stu;
}
/// <summary>
/// 返回DataSet数据类型
/// </summary>
/// <returns>DataSet</returns>
[WebMethod]
public DataSet GetDataSet()
{
DataSet ds = new DataSet();
return ds;
}
}
#region 定义可序列化类
/*
* 为避免Framework1.1中返回实体类报错“请求格式无法识别。”
* 要在Web.Config文件中<system.web>添加以下内容:
* <webServices>
<protocols>
<add name="HttpPost" />
<add name="HttpGet" />
</protocols>
</webServices>
*/
//指示下面的类可序列化
/// <summary>
/// 学生基本信息类
/// </summary>
[Serializable]
public class Student
{
/// <summary>
/// 构造函数
/// </summary>
public Student()
{
}
private string name;
/// <summary>
/// 姓名
/// </summary>
public string Name
{
get
{
return name;
}
set
{
name=value;
}
}
private bool sex;
/// <summary>
/// 性别--布尔型变量真为女,假为男
/// </summary>
public bool Sex
{
get
{
return sex;
}
set
{
sex=value;
}
}
private int age;
/// <summary>
/// 年龄
/// </summary>
public int Age
{
get
{
return age;
}
set
{
age=value;
}
}
}
#endregion
}
调用WebService服务示例代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using StudentClient.localhost;
namespace StudentClient
{
/// <summary>
/// FrmDemo 的摘要说明。
/// </summary>
public class FrmDemo : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button btnStu;
private System.Windows.Forms.Button btnInt;
private System.Windows.Forms.Button btnHello;
private System.Windows.Forms.Button btnDataSet;
private System.Windows.Forms.Button btnBool;
private System.Windows.Forms.TextBox txtSex;
private System.Windows.Forms.TextBox txtAge;
private System.Windows.Forms.TextBox txtOther;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public FrmDemo()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.txtSex = new System.Windows.Forms.TextBox();
this.txtAge = new System.Windows.Forms.TextBox();
this.txtOther = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.btnStu = new System.Windows.Forms.Button();
this.btnInt = new System.Windows.Forms.Button();
this.btnHello = new System.Windows.Forms.Button();
this.btnDataSet = new System.Windows.Forms.Button();
this.btnBool = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 0;
this.label1.Text = "姓名:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(32, 70);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 16);
this.label2.TabIndex = 1;
this.label2.Text = "性别:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(136, 70);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 16);
this.label3.TabIndex = 2;
this.label3.Text = "年龄:";
//
// label4
//
this.label4.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label4.Location = new System.Drawing.Point(72, 8);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(136, 24);
this.label4.TabIndex = 3;
this.label4.Text = "学生基本信息";
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(80, 36);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(144, 21);
this.txtName.TabIndex = 4;
this.txtName.Text = "";
//
// txtSex
//
this.txtSex.Location = new System.Drawing.Point(80, 64);
this.txtSex.Name = "txtSex";
this.txtSex.Size = new System.Drawing.Size(48, 21);
this.txtSex.TabIndex = 5;
this.txtSex.Text = "";
//
// txtAge
//
this.txtAge.Location = new System.Drawing.Point(184, 64);
this.txtAge.Name = "txtAge";
this.txtAge.Size = new System.Drawing.Size(40, 21);
this.txtAge.TabIndex = 6;
this.txtAge.Text = "";
//
// txtOther
//
this.txtOther.Location = new System.Drawing.Point(80, 96);
this.txtOther.Name = "txtOther";
this.txtOther.Size = new System.Drawing.Size(128, 21);
this.txtOther.TabIndex = 7;
this.txtOther.Text = "";
//
// label5
//
this.label5.Location = new System.Drawing.Point(32, 100);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(48, 16);
this.label5.TabIndex = 8;
this.label5.Text = "其它:";
//
// btnStu
//
this.btnStu.Location = new System.Drawing.Point(8, 128);
this.btnStu.Name = "btnStu";
this.btnStu.Size = new System.Drawing.Size(88, 24);
this.btnStu.TabIndex = 9;
this.btnStu.Text = "调用Student";
this.btnStu.Click += new System.EventHandler(this.btnStu_Click);
//
// btnInt
//
this.btnInt.Location = new System.Drawing.Point(200, 128);
this.btnInt.Name = "btnInt";
this.btnInt.Size = new System.Drawing.Size(32, 24);
this.btnInt.TabIndex = 10;
this.btnInt.Text = "Int";
this.btnInt.Click += new System.EventHandler(this.btnInt_Click);
//
// btnHello
//
this.btnHello.Location = new System.Drawing.Point(152, 128);
this.btnHello.Name = "btnHello";
this.btnHello.Size = new System.Drawing.Size(48, 24);
this.btnHello.TabIndex = 11;
this.btnHello.Text = "Hello";
this.btnHello.Click += new System.EventHandler(this.btnHello_Click);
//
// btnDataSet
//
this.btnDataSet.Location = new System.Drawing.Point(96, 128);
this.btnDataSet.Name = "btnDataSet";
this.btnDataSet.Size = new System.Drawing.Size(56, 24);
this.btnDataSet.TabIndex = 12;
this.btnDataSet.Text = "DataSet";
this.btnDataSet.Click += new System.EventHandler(this.btnDataSet_Click);
//
// btnBool
//
this.btnBool.Location = new System.Drawing.Point(232, 128);
this.btnBool.Name = "btnBool";
this.btnBool.Size = new System.Drawing.Size(40, 24);
this.btnBool.TabIndex = 13;
this.btnBool.Text = "Bool";
this.btnBool.Click += new System.EventHandler(this.btnBool_Click);
//
// FrmDemo
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(280, 158);
this.Controls.Add(this.btnBool);
this.Controls.Add(this.btnDataSet);
this.Controls.Add(this.btnHello);
this.Controls.Add(this.btnInt);
this.Controls.Add(this.btnStu);
this.Controls.Add(this.label5);
this.Controls.Add(this.txtOther);
this.Controls.Add(this.txtAge);
this.Controls.Add(this.txtSex);
this.Controls.Add(this.txtName);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FrmDemo";
this.Text = "FrmDemo";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 调用学生信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStu_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
//调用返回实体类服务方法
Student stu = dm.GetStudent();
txtName.Text = stu.Name;
txtSex.Text = (stu.Sex==false?"女":"男");
txtAge.Text = stu.Age.ToString();
}
/// <summary>
/// DataSet数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDataSet_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
txtOther.Text = dm.GetDataSet().Tables.Count.ToString();
}
/// <summary>
/// 返回字符串
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnHello_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
txtOther.Text = dm.HelloWorld();
}
/// <summary>
/// 返回整型
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnInt_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
txtOther.Text = dm.GetInt().ToString();
}
/// <summary>
/// 返回布尔型
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnBool_Click(object sender, System.EventArgs e)
{
//实例化服务类
Demo dm = new Demo();
txtOther.Text = dm.GetBool().ToString();
}
}
}
窗体界面如下图:
相关文章推荐
- C# 中WebService返回类型(string,int,bool,DataSet,class实体类)示例
- C# 中WebService返回类型(string,int,bool,DataSet,class实体类)示例
- C# 中WebService返回类型(string,int,bool,DataSet,class实体类)示例
- 【工作记录0022】C#(.NET)调用Java开发的WebService(wsdl),客户端传递非string类型参数(int,double,bool等),而服务端无法获取到参数值的解决方案
- C#控制台基础 返回类型为string的 int 类型参数的委托与拉姆塔表达式
- C#控制台基础 func<int,string> int类型参数与string类型返回值
- c#实例化继承类,必须对被继承类的程序集做引用 .net core Redis分布式缓存客户端实现逻辑分析及示例demo 数据库笔记之索引和事务 centos 7下安装python 3.6笔记 你大波哥~ C#开源框架(转载) JSON C# Class Generator ---由json字符串生成C#实体类的工具
- WebService传递XML数据 C#DataSet操作XML 解析WebService返回的XML数据
- C#读取数据库返回泛型集合 把DataSet类型转换为List<T>泛型集合
- C#实现String类型和json之间的相互转换功能示例
- 如果不空null并且不是空字符串才去修改这个值,但这样写只能针对字符串(String)类型,如果是Integer类型的话就会有问题了。 int i = 0; i!=''。 mybatis中会返回tr
- 速战速决 (2) - PHP: 数据类型 bool, int, float, string, object, array
- C#枚举 枚举和int以及string类型之间的转换 结构 重载 全局变量
- c#无法将类型int隐式转换为string怎么解决?
- 复杂类型(除int,uint,number,string,bool)比较运行情况
- "int i=1" "int i=new int() "和“String str = "a";” “String str = new String("a")”区别以及c#值类型和引用类型
- 将两个Int类型数组连接为一个string类型数组(C#)
- 在C#中int,string等各种类型之间的相互转换--现在写点技术文档
- gsoap 访问c# webservice 返回数据集的示例小结
- c#之枚举类型和int以及string类型的转换