📄 customsoapheaderform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using MobileDevelopersHandbook.CustomSoapHeadersService;
namespace MobileDevelopersHandbook
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class CustomSOAPheaderForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private readonly string WebServiceURL = "http://myServer/CustomSoapHeadersService/CustomSoapHeadersService.asmx";
public CustomSOAPheaderForm()
{
//
// 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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
//
// label1
//
this.label1.Location = new System.Drawing.Point(0, 192);
this.label1.Size = new System.Drawing.Size(240, 80);
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 24);
this.button1.Size = new System.Drawing.Size(176, 32);
this.button1.Text = "Invoke - no header";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(32, 80);
this.button2.Size = new System.Drawing.Size(176, 32);
this.button2.Text = "Invoke - wrong password";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(32, 136);
this.button3.Size = new System.Drawing.Size(176, 35);
this.button3.Text = "Invoke - correct credentials";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// CustomSOAPheaderForm
//
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.MinimizeBox = false;
this.Text = "Form1";
}
#endregion
static void Main()
{
Application.Run(new CustomSOAPheaderForm());
}
private void button1_Click(object sender, System.EventArgs e)
{
invokeIt(null);
}
private void button2_Click(object sender, System.EventArgs e)
{
AuthHeader hdr = new AuthHeader();
hdr.Username = "andy";
hdr.Password = "WRONG";
invokeIt(hdr);
}
private void button3_Click(object sender, System.EventArgs e)
{
AuthHeader hdr = new AuthHeader();
hdr.Username = "andy";
hdr.Password = "P455w0rd";
invokeIt(hdr);
}
private void invokeIt(AuthHeader hdr)
{
System.Diagnostics.Debug.Assert(this.WebServiceURL.IndexOf("myServer") != -1, "You must change the calue of the WebServiceURL field to the URL where you have installed the BasicAuthService Web Service");
SOAPheaderService ws = new SOAPheaderService();
ws.Url = this.WebServiceURL;
ws.AuthHeaderValue = hdr;
try
{
bool response = ws.Authenticate();
label1.Text = "Web Service returned: " + response.ToString();
}
catch (System.Web.Services.Protocols.SoapException exp)
{
label1.Text = "SOAP exception, message: " + exp.Message;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -