using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.Services;
using
System.Web.Script.Services;
using
System.Web.Script.Serialization;
using
System.Text;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
[WebMethod]
[ScriptMethod]
public
static
string
GetAllProducts()
{
System.Threading.Thread.Sleep(3000);
StringBuilder sb =
new
StringBuilder();
JavaScriptSerializer json =
new
JavaScriptSerializer();
List<Product> products = ProductDAL.GetProducts();
json.Serialize(products, sb);
return
sb.ToString();
}
}
public
class
Product
{
public
int
ProductID {
get
;
set
; }
public
string
ProductName {
get
;
set
; }
public
string
Description {
get
;
set
; }
}
public
class
ProductDAL
{
public
static
List<Product> GetProducts()
{
return
new
List<Product>()
{
new
Product() {ProductID = 1, ProductName =
"Apple"
, Description =
"Desc01 Goes here"
},
new
Product() {ProductID = 2, ProductName =
"Banana"
, Description =
"Desc02 Goes here"
},
new
Product() {ProductID = 3, ProductName =
"Rice"
, Description =
"Desc03 Goes here"
},
new
Product() {ProductID = 4, ProductName =
"Grapes"
, Description =
"Desc04 Goes here"
},
new
Product() {ProductID = 5, ProductName =
"Beans"
, Description =
"Desc05 Goes here"
},
};
}
}