An example:
1. In .aspx:
Server processing, please wait
2. In WebService:
[WebService( Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//To allow this web service to be called from scripts using ASP.NET AJAX, cancel Comments on the following line.
[System.Web.Script.Services.ScriptService] //If you want to use jquery to call WebService, uncomment the previous one
public class WebService : System.Web.Services.WebService
{
public WebService ()
{
//If using designed components, uncomment the following lines
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string GetWish(string value1, string value2, string value3, int value4)
{
return string .Format("Wish you {0}, {1}, {2} in {3} years", value1, value2, value3, value4);
}
[WebMethod]
public List< int> GetArray(int i)
{
List list = new List();
while (i >= 0)
{
list.Add( i--);
}
return list;
}
[WebMethod]
public Class1 GetClass()
{
Class1 a = new Class1();
a.ID = "1";
a.Value = "Good luck in the Year of the Ox";
return a;
}
[WebMethod]
public DataSet GetDataSet()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("Table1");
dt.Columns.Add("ID", Type.GetType("System.String"));
dt.Columns.Add("Value", Type.GetType("System.String"));
DataRow dr = dt.NewRow();
dr["ID"] = "1" ;
dr["Value"] = "Happy New Year";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["ID"] = " 2";
dr["Value"] = "All the best";
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return ds;
}
}
//Customized class, only two attributes
public class Class1
{
public string ID { get; set; }
public string Value { get ; set; }
}
3. In JS:
4. Effect