⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callwsform.cs

📁 清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using MobileDevelopersHandbook.BasicAuthService;
using System.Net;

namespace MobileDevelopersHandbook
{
	/// <summary>
	/// Summary description for CallWSForm.
	/// </summary>
	public class CallWSForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox UsernameTextBox;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox PasswordTextBox;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label ResponseLabel;

        private readonly string WebServiceURL = "http://myServer/BasicAuthService/Service.asmx";
	
		public CallWSForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.UsernameTextBox = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.PasswordTextBox = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.ResponseLabel = new System.Windows.Forms.Label();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 40);
			this.label1.Text = "Username";
			// 
			// UsernameTextBox
			// 
			this.UsernameTextBox.Location = new System.Drawing.Point(96, 39);
			this.UsernameTextBox.Size = new System.Drawing.Size(128, 22);
			this.UsernameTextBox.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 88);
			this.label2.Text = "Password";
			// 
			// PasswordTextBox
			// 
			this.PasswordTextBox.Location = new System.Drawing.Point(96, 87);
			this.PasswordTextBox.PasswordChar = '*';
			this.PasswordTextBox.Size = new System.Drawing.Size(128, 22);
			this.PasswordTextBox.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(49, 144);
			this.button1.Size = new System.Drawing.Size(142, 48);
			this.button1.Text = "Invoke Web Service";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// ResponseLabel
			// 
			this.ResponseLabel.Location = new System.Drawing.Point(20, 216);
			this.ResponseLabel.Size = new System.Drawing.Size(200, 48);
			this.ResponseLabel.Text = "Response:";
			// 
			// CallWSForm
			// 
			this.ClientSize = new System.Drawing.Size(240, 270);
			this.Controls.Add(this.ResponseLabel);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.PasswordTextBox);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.UsernameTextBox);
			this.Controls.Add(this.label1);
			this.MinimizeBox = false;
			this.Text = "CallWSForm";

		}
		#endregion

		static void Main() 
		{
			Application.Run(new CallWSForm());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
            //Check that the Web Service URL is updated
            System.Diagnostics.Debug.Assert(this.WebServiceURL.IndexOf("myServer") != -1, "You must change the value of the WebServiceURL field to the URL where you have installed the BasicAuthService Web Service");

			BasicAuthWebService ws = new BasicAuthWebService();
            ws.Url = this.WebServiceURL;

			// Create a NetworkCredential object with the username 
			// and password as entered in the Textbox controls
			NetworkCredential creds = new NetworkCredential(
				UsernameTextBox.Text, PasswordTextBox.Text);
			// Use this NetworkCredential object with the Web service proxy
			ws.Credentials = creds;

			try
			{
				ResponseLabel.Text = ws.HelloWorld();
			}
			catch (Exception exp)
			{
				ResponseLabel.Text = exp.Message;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -