创建Asp.Net Web 服务应用程序
创建Asp.Net Web 服务应用程序
1.打开vs2010,创建项目,选择.net frame work 3.5,.net4.0为什么没有 Web 服务应用程序 不知道
<1>添加一个求和的方法
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int Add(int a,int b)
{
return a+b;
}
2.部署到iis上:http://localhost:100/Service1.asmx,打开这个地址可查看是否工作正常
3.打开另外一个vs2010窗口,创建一个Web应用程序
<1>在bin上右击添加服务引用
<2>将Web引用的名称改成myFirstService
<3>在页面上引用命名空间(myCaller是自己的应用程序名) using myCaller.myFirstService;
<4>
protected void Page_Load(object sender, EventArgs e)
{
Service1SoapClient objDealer = new Service1SoapClient();
int intResult = objDealer.Add(1, 2);
Response.Write(intResult);
}
浙公网安备 33010602011771号