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