WebService代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
namespace jQuery.Learning
{
  /// <summary>
  /// WebService1 的摘要说明
  /// </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 WebService1 : System.Web.Services.WebService
  {
    /// <summary>
    /// 无参数
    /// </summary>
    /// <returns></returns>
    [WebMethod]
    public string HelloWorld()
    {
      return "Hello World ";
    }
    /// <summary>
    /// 带参数
    /// </summary>
    /// <param name="value1"></param>
    /// <param name="value2"></param>
    /// <param name="value3"></param>
    /// <param name="value4"></param>
    /// <returns></returns>
    [WebMethod]
    public string GetWish(string value1, string value2, string value3, int value4)
    {
      return string.Format("祝您在{3}年里 {0}、{1}、{2}", value1, value2, value3, value4);
    }
    /// <summary>
    /// 返回集合
    /// </summary>
    /// <param name="i"></param>
    /// <returns></returns>
    [WebMethod]
    public List<int> GetArray(int i)
    {
      List<int> list = new List<int>();
      while (i >= 0)
      {
        list.Add(i--);
      }
      return list;
    }
    /// <summary>
    /// 返回一个复合类型
    /// </summary>
    /// <returns></returns>
    [WebMethod]
    public Class1 GetClass()
    {
      return new Class1 { ID = "1", Value = "牛年大吉" };
    }

 

前台代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
  </div>
  </form>
</body>
</html>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2021-05-09
相关资源
相似解决方案