加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

调用WebService方法

发布时间:2020-12-17 02:08:12 所属栏目:安全 来源:网络整理
导读:?通过脚本调用: %@ Page Language="C#" AutoEventWireup="true" CodeFile="default3.aspx.cs" Inherits="default3" %!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"html xmlns

?通过脚本调用:

通过添加web引用调用:

调用本地解决方案中的WebService

添加新项->Web服务(WebService.asmx)

在WebService.cs中添加方法(简单加法)Add(int a,int b)

代码:

[WebMethod]
?public int Add(int a,int b) {
??????? return a+b;
?}

保存

在WebPage(Default.aspx)中调用

先添加web引用->此解决方案中的Web服务->添加WebService.asmx引用(引用名;testWebService)

在Default.aspx中的添加TextBox1,TextBox2,label1,button1

在button1的触发事件中添加调用代码:

testWebService.WebService test=new testWebService();

int a=Convert.ToInt32(TextBox1.text);

int b=Convert.ToInt32(TextBox2.text);

int c;

c=test.Add(a,b);

label1.text=c.toString();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读