All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
两台Sql,server数据同步_[SQL,Server教程]
巧用Asp.net代码在虚拟主机实现Urlrewrite_[Asp.Net教程]
PHP动态网页编程:include()与require()的对比_php资料_编程技术
PHP和MYSQL联合打造简单留言本程序_php资料_编程技术
AJAX编程实践之与服务器通信_[AJAX教程]
ASP.NET中的日期与时间的处理方法_.net资料_编程技术
HTML教程-收集的常用的HTML标签(4)_[Html教程]
.net基础知识错误注意二十二点知识_.net资料_编程技术
实例讲解动态网页技术PHP开发文件系统_php资料_编程技术
C#中Label控件应用实例
Reading number is top 10 pictures
Photographed the passion of the clients and prostitutes in the sex trade picture2
美女浴室写真1
9.3阅兵全景图5-地空反舰导弹梯队
Summer is most suitable for young people to travel in China9
Hunan road lawenforcement vehicle pursue overload car caused the car turn and man is died
到南昌西站了2
Absolutely shocked. National geographic 50 animal photographys4
小学生考试又现神作--还有外国的
青春清纯美女大集合4
中国女孩大胆自拍,显露完美身材
Download software ranking
Tram sex maniac 2 (H) rar bag1
Detective task-the top secret prostitution files
Twenty piece of palm leaf
Sora aoi's film--cangkong_Blue.Sky
Ashlynn Video2
Unix video tutorial14
Desire a peach blossom
Professional killers2 data package
Boxer vs Yellow3
White deer villiage
qq published in(发表于) 2014/7/11 9:23:52 Edit(编辑)
C#教程:客户机调用Web服务应用实例

C#教程:客户机调用Web服务应用实例

C#教程:客户机调用Web服务应用实例

客户机调用Web服务

(1)新建一个名为MrWeb的项目。在Visual Studio 2005开发环境中,选择“文件”/“新建”/“网站”选项,弹出“新建网站”对话框,该对话框中选择“ASP.NET 网站”选项,并将其名称命名为“MrWeb”,如图1所示。

(2)新建项目的默认主页为Default.aspx,该页面的设计结果如图2所示。

(3)引用Web服务。在“解决方案资源管理器”窗口中,选中当前项目,单击鼠标右键,在弹出的快捷菜单中选择“添加Web引用”选项,弹出“添加Web引用”对话框,该对话框中,用户可查找本地计算机上的Web服务,也可以查找网络上的Web服务,如图3所示。



图1 创建ASP.NET 网站



图2 Default.aspx页面设计

(4)由于本实例调用的Web服务在本机上,在地址栏输入Web服务的地址:http://localhost: 1333/mrWebService/Service.asmx单击【前往】按钮,出现Web服务页面。

(5)在“Web引用名”文本框中输入“MrService”,如图4所示,然后单击【添加引用】按钮,把引用添加到项目中,这时在“解决方案资源管理器”窗口中,将会看到刚才添加的Web服务,如图5所示。



图3 “添加Web引用”对话框



图4 Web服务页面



图5 添加的Web引用

(6)程序主要代码。

在页面设计视图中,Button1单击事件调用Add方法代码如下:

protected void Button1_Click(object sender, EventArgs e)

{ //调用Web服务的实例

MrService.Service myService = new MrService.Service();

//调用Web服务的Add方法

this.TextBox3.Text = myService.Add (Convert.ToInt33 (this.TextBox1.Text), Convert.ToInt33 (this.TextBox2.Text)). ToString();

}

Button2单击事件调用Ascii方法代码如下:

protected void Button2_Click(object sender, EventArgs e)

{

//调用Web服务的实例

MrService.Service myService = new MrService.Service();

//调用Web服务的Ascii方法

char charscii = myService.Ascii(this.TextBox4.Text);

int d = Convert.ToInt33(charscii);

this.TextBox5.Text = Convert.ToString(d);

}

Button3按钮的单击事件调HelloWorld方法用代码:

protected void Button3_Click(object sender, EventArgs e)

{ //调用Web服务的实例

MrService.Service myService = new MrService.Service();

//调用Web服务的HelloWorld方法

this.TextBox6.Text = myService.HelloWorld();

}

示例运行结果如图6所示。



图6 调用Web服务效果




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.