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

webservices创建和引用

发布时间:2020-12-17 02:39:03 所属栏目:安全 来源:网络整理
导读:Service端 %@ WebService Language="C#" Class="MathService" % using System; using System.Web.Services; [WebService(Namespace="Microsoft.Samples.XmlMessaging.WebServices")] public class MathService { ?? [WebMethod] ?? public float Add(float a

Service端

<%@ WebService Language="C#" Class="MathService" %>
using System;
using System.Web.Services;
[WebService(Namespace="Microsoft.Samples.XmlMessaging.WebServices")]
public class MathService {
?? [WebMethod]
?? public float Add(float a,float b)
?? {
?????? return a + b;
?? }
?? [WebMethod]
?? public float Subtract(float a,float b)
?? {
?????? return a - b;
?? }
?? [WebMethod]
?? public float Multiply(float a,float b)
?? {
?????? return a * b;
?? }
?? [WebMethod]
?? public float Divide(float a,float b)
?? {
?????? if (b==0) return -1;
?????? return a / b;
?? }
}



CLIENT端
先运行server端得到访问地址
然后添加web引用 把网址打进去 改引用名
建立一个按扭
事件
????????private void button1_Click(object sender,EventArgs e)
????????{
????????????TestSvr.MathService tt = new TestSvr.MathService();
????????????MessageBox.Show(tt.Add(1,2).ToString(),"调用Web Services");
????????}

TestSvr为WEB引用名
这样就很明显了

?

引用

http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/webservices/samples/MathService/MathService.src&file=cs/Client/MathServiceClient.aspx&lang=C%23+Source

?

http://blog.csdn.net/lllxy/archive/2008/01/22/2060070.aspx

(编辑:李大同)

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

    推荐文章
      热点阅读