Click here to Skip to main content
15,881,803 members
Articles / Web Development / ASP.NET

Prepare a JSON Web Service and access it with JQuery

Rate me:
Please Sign up or sign in to vote.
4.88/5 (52 votes)
6 Jul 2009CPOL10 min read 364.5K   9.9K   149  
Returing JSON data from a Web Service and accessing it with JQuery.
using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// This class is like Business layer facade which will fetch data from Data Access Layer.
/// For simpliciy this class generate dummy data.
/// </summary>
public class ProductFacade
{
    #region Constructor
    public ProductFacade()
    {
    } 
    #endregion

    /// <summary>
    /// Get all products
    /// </summary>
    /// <returns>List of products</returns>
    public static List<Product> GetAllProducts()
    {
        List<Product> products = new List<Product>();
        Product p = default( Product);
        for (int i = 1; i <= 10; i++)
        {
            p = new Product();
            p.ProductCode =string.Format( "p_{0}",i);
            p.ProductID = i;
            p.ProductName =string.Format( "Product {0}",i);
            products.Add(p);
        }
        return products;
    }
    /// <summary>
    /// Get all Proudcts starting with prefix provided
    /// </summary>
    /// <param name="prefix">product name prefix</param>
    /// <returns></returns>
    public static List<Product> GetProducts(string prefix)
    {
        List<Product> products = new List<Product>();
        Product p = default(Product);
        for (int i = 1; i <= 10; i++)
        {
            p = new Product();
            p.ProductCode = string.Format("p_{0}", i);
            p.ProductID = i;
            p.ProductName = string.Format("{0} Product {1}",prefix, i);
            products.Add(p);
        }
        return products;
    }
    
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect ImpleVista Aps
Denmark Denmark
Sohel has more than six years of experience in professional software development with extensive involvement in Web based Object-Oriented, Multi-Tiered application design and development. He's Familiar with Test Driven Development (TDD) and refactoring techniques as well as having expertise in architecturing large enterprise applications. He has Experience in working with Content Management System and Portal Management System tools like SharePoint, DotNetNuke, Ektron.

Over last few years, he’s involved in development with projects on Microsoft SharePoint and received Microsoft MVP for SharePoint Server Development in the year 2011 and 2012. Currently he's working in a software company located Copenhagen,Denmark on a project integrating SharePoint and SAP. You can read his popular blog at: http://ranaictiu-technicalblog.blogspot.com

Comments and Discussions