1、添加web服务。

webservice简单例子-LMLPHP

/// <summary>
/// demo 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
//[System.Web.Script.Services.ScriptService]
public class demo : System.Web.Services.WebService
{ [WebMethod]
public string HelloWorld()
{
return "Hello World";
} [WebMethod]
public int GetSum(int a, int b)
{
return a + b;
}
}

2、添加服务引用:地址为上一步添加的web服务访问地址,高级=》添加web引用=》添加引用。

webservice简单例子-LMLPHP

webservice简单例子-LMLPHP

webservice简单例子-LMLPHP

3、调用

public ActionResult GetSum(int a, int b)
{
localhost.demo s = new localhost.demo();
var sum = s.GetSum(a, b);
return Content(sum.ToString());
}
04-26 17:56
查看更多