Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 3k
Category:

ADO-ODBC

Development Platform:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using ch8_2.localhost;
  8.  
  9. namespace ch8_2
  10. {
  11. /// <summary>
  12. /// Form1 的摘要说明。
  13. /// </summary>
  14. public class Form1 : System.Windows.Forms.Form
  15. {
  16. private System.Windows.Forms.Button button1;
  17. private System.Windows.Forms.TextBox textBox1;
  18. private System.Windows.Forms.Label label1;
  19. /// <summary>
  20. /// 必需的设计器变量。
  21. /// </summary>
  22. private System.ComponentModel.Container components = null;
  23. public Form1()
  24. {
  25. //
  26. // Windows 窗体设计器支持所必需的
  27. //
  28. InitializeComponent();
  29. //
  30. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  31. //
  32. }
  33. /// <summary>
  34. /// 清理所有正在使用的资源。
  35. /// </summary>
  36. protected override void Dispose( bool disposing )
  37. {
  38. if( disposing )
  39. {
  40. if (components != null) 
  41. {
  42. components.Dispose();
  43. }
  44. }
  45. base.Dispose( disposing );
  46. }
  47. #region Windows Form Designer generated code
  48. /// <summary>
  49. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  50. /// 此方法的内容。
  51. /// </summary>
  52. private void InitializeComponent()
  53. {
  54. this.button1 = new System.Windows.Forms.Button();
  55. this.textBox1 = new System.Windows.Forms.TextBox();
  56. this.label1 = new System.Windows.Forms.Label();
  57. this.SuspendLayout();
  58. // 
  59. // button1
  60. // 
  61. this.button1.Location = new System.Drawing.Point(192, 136);
  62. this.button1.Name = "button1";
  63. this.button1.TabIndex = 0;
  64. this.button1.Text = "显示时间";
  65. this.button1.Click += new System.EventHandler(this.button1_Click);
  66. // 
  67. // textBox1
  68. // 
  69. this.textBox1.Location = new System.Drawing.Point(32, 80);
  70. this.textBox1.Name = "textBox1";
  71. this.textBox1.Size = new System.Drawing.Size(236, 21);
  72. this.textBox1.TabIndex = 1;
  73. this.textBox1.Text = "";
  74. // 
  75. // label1
  76. // 
  77. this.label1.Location = new System.Drawing.Point(32, 40);
  78. this.label1.Name = "label1";
  79. this.label1.Size = new System.Drawing.Size(192, 23);
  80. this.label1.TabIndex = 2;
  81. this.label1.Text = "使用Web Service的方法显示时间";
  82. // 
  83. // Form1
  84. // 
  85. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  86. this.ClientSize = new System.Drawing.Size(292, 221);
  87. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  88.   this.label1,
  89.   this.textBox1,
  90.   this.button1});
  91. this.Name = "Form1";
  92. this.Text = "使用XML Web Service";
  93. this.ResumeLayout(false);
  94. }
  95. #endregion
  96. /// <summary>
  97. /// 应用程序的主入口点。
  98. /// </summary>
  99. [STAThread]
  100. static void Main() 
  101. {
  102. Application.Run(new Form1());
  103. }
  104. private void button1_Click(object sender, System.EventArgs e)
  105. {
  106. try
  107. //创建一个Web Service的实例
  108. Service1 service=new Service1();
  109. //调用其中的方法
  110. this.textBox1.Text=service.MycomputerTime();
  111. }
  112. catch (Exception error)
  113. {
  114.    //错误处理
  115.    MessageBox.Show("调用Web Service时出现错误:"+error.Message,"错误",
  116.    MessageBoxButtons.OK,MessageBoxIcon.Warning);
  117. }
  118. }
  119. }
  120. }