云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > c#-操作webservice(经典入门教程)

c#-操作webservice(经典入门教程)

  • 62 次阅读
  • 3 次下载
  • 2025/5/29 21:22:31

\http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\ 无标题页

+

<%@ Page Language=\

AutoEventWireup=\CodeFile=\Inherits=\

无标题页

然后在后台写调用的代码,调用之前和使用其它的对象一样,要先实例化,实例化的方法是localhost.Service a = new localhost.Service();然后就可以通过a来访问WebService里面提供的方法了。在这个例子里面,动态的创建了一个button控件来触发WebService的调用,后台代码如下:

运行后可以看到效果,如下图所示,在前面两个Textbox里面输入两个操作数,在中间的下拉列表中选择操作符,然后点击\号,将计算的结果输出到第三个Textbox里面。

而整个计算并不是在本地进行的,是在Web服务端进行计算的然后将结果通过XML返还给了调用方的,所以,在运行该程序的时候,WebService程序还必须启动,否则会报无法连接远程服务器的异常,如下图:

后台代码如下:

view plaincopy to clipboardprint? using System;

using System.Configuration; using System.Data; using System.Linq; using System.Web;

using System.Web.Security; using System.Web.UI;

using System.Web.UI.HtmlControls; using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts; using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) { }

protected void Button1_Click(object sender, EventArgs e) {

string selectFlag = selectOper.Value;

localhost.Service web = new localhost.Service(); if (selectFlag.Equals(\ {

Result.Text

=(web.addition(double.Parse(Num1.Text),double.Parse(Num2.Text))).ToString();

}

else if (selectFlag.Equals(\ {

Result.Text = (web.subtract(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString(); }

else if (selectFlag.Equals(\ {

Result.Text = (web.multiplication(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString(); }

else if (selectFlag.Equals(\ {

Result.Text = (web.division(double.Parse(Num1.Text), double.Parse(Num2.Text))).ToString(); } } }

using System;

using System.Configuration; using System.Data; using System.Linq; using System.Web;

using System.Web.Security; using System.Web.UI;

using System.Web.UI.HtmlControls; using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts; using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e) { }

protected void Button1_Click(object sender, EventArgs e) {

string selectFlag = selectOper.Value;

搜索更多关于: c#-操作webservice(经典入门教程) 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

\http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com