xml实验指导书(5)

2019-08-01 22:57

《XML技术及应用》实验指导书

2.创建Web窗体调用Web服务 (1)打开Visual Studio 2005 ,选择“文件”,再选择“新建网站”,再选择“ASP.NET 网站”,选择文件系统路径(与ASP.NET Web服务的路径不同),确定结束。 (2)创建Web窗体WSCustomer.aspx。如下图所示:

(3)在解决方案管理器右击“添加

Web引用”,在地址栏输入:

http://localhost:1125/WebSite2/SumAddService.asmx,具体路径根据创建Web服务时而定。更改web引用名为:myws,点击“添加web引用”结束。 (4)WSCustomer.aspx如下:

<%@ Page Language=\ CodeFile=\Inherits=\

Web服务测试实例

(5) WSCustomer.aspx.cs如下:

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Collections; using System.ComponentModel; using System.Drawing; using System.Web.SessionState;

namespace webdemo {

public partial class WSCustomer : System.Web.UI.Page { myws.SumAddService customer; //声明Web服务代理类 protected void Page_Load(object sender, EventArgs e) { customer = new myws.SumAddService(); //实例化Web服务代理类 if (!Page.IsPostBack) {

Label5.Visible = false; TextBox3.Visible = false; } }

#region Web 窗体设计器生成的代码

override protected void OnInit(EventArgs e) {

// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 InitializeComponent();

22

《XML技术及应用》实验指导书

base.OnInit(e); }

/// 设计器支持所需的方法 - 不要使用代码编辑器修改此方法的内容。 private void InitializeComponent() { this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);

this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); }

#endregion

private void Button1_Click(object sender, System.EventArgs e) { if (DropDownList1.SelectedIndex == 0)

//当选择运算为加法时,调用Web服务方法Add。注意进行数据类型的转换 Label7.Text = customer.Add(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)).ToString();

else //当选择运算为平均值时,调用Web服务方法Average。注意进行数据类型的转换 Label7.Text = customer.Average(Convert.ToInt32(TextBox1.Text),

Convert.ToInt32(TextBox2.Text), Convert.ToInt32(TextBox3.Text)).ToString(); }

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { if (DropDownList1.SelectedIndex == 0) { //当选择运算为加法时,隐藏第3个文本框 Label5.Visible = false; TextBox3.Visible = false; }

else { //当选择运算为平均值时,显示第3个文本框

[3] } } } }

在[3]添加代码,显示标签Label5和第3个文本框TextBox3。

(6)选择菜单“生成”,再选择“生成网站”;选择菜单“调试”,再选择“启动调试”。观察调用Web服务的测试页面。如下图所示:

五、思考题

(1)Web服务有什么优点?

23

《XML技术及应用》实验指导书

(2)WSDL文档的用途是什么?

六、参考文献

顾兵 主编,XML实用技术教程,清华大学出版社,237-250页,2007年1月

24


xml实验指导书(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:廉洁风险排查防控工作报告2018

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: