微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

webservices创建和引用

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐