讲一个例子
新建一个Web Service,在[WebMethod]下添加一个函数或过程
如:
public string F(int n)
{int s=1;
for(int i=1;i<=n;i++)s*=i;
return s.ToString();
}F5编译运行,生成asmx文件然后在其它程序中就可以使用"添加Web引用"来调用这个Web服务(函数)
新建一个Web Service,在[WebMethod]下添加一个函数或过程
如:
public string F(int n)
{int s=1;
for(int i=1;i<=n;i++)s*=i;
return s.ToString();
}F5编译运行,生成asmx文件然后在其它程序中就可以使用"添加Web引用"来调用这个Web服务(函数)
建一个个simple.asmx%@ WebService Language="C#" Class="HelloWorld" %>using System;
using System.Web;
using System.Web.Services;public class HelloWorld: WebService {
[WebMethod]
public string SayHelloWorld() {
return "Hello World";
}
}将之拷到intpub/wwwroot下
只有一个方法
然后,在command中利用命令WSDL http://youemachinename/simple.asmx?WSDL /out:HelloWord.cs /namespace:learn上面的命令生成代理类HelloWord.cs,在你的当前命令行目录下将代理类加入你所要调用webservice的工程
using learn;....void Page_Load(object sender, EventArgs e) {
HelloWord hello = new HelloWord();
Response.Write(hello.SayHelloWorld());
}这样调用就可以,你可以在另外一台机上试,尝试关闭有simple.asmx机器的www服务器,再调用.