Cappuccino Javascript Framework – Part 1

Consuming .NET JSON WebService – Part 1

The .NET WebService

On this post I’ll show you HOW-TO develop and consuming JSON Web Services using the Cappuccino Javascript Framework and .Net 2.0 / 3.5 Framework.

In first step, let’s build the JSON .Net WebService, using Microsoft or Mono Framework. To simplify this post I’ll not use the code behind.

As we know, to use JSON on .NET WebServices we need to use the following assembly “Microsoft.Web.Extensions.dll”, and in the code we need to define the following namespaces: System.Web.Script.Services, System.Web.Script.Serialization.

Ok, let’s start writing the .Net JSON WebService (XmlJson.asmx) code:

<%@ WebService Language="C#" Class="Services.XmlJson" %>
using System;
using System.Globalization;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

// Script namespace from Microsoft.Web.Extensions.dll assembly
using System.Web.Script.Services;
using System.Web.Script.Serialization;

namespace Services

    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    // To allow this Web Service to be called from script, using ASP.NET AJAX. 
    public class XmlJson : System.Web.Services.WebService

        private Contact _Contact;

        public XmlJson() { }

        public string About()
            return "Version 1.0";

        // ResponseFormat is JSON
        public string ListJSON()
            ArrayList list = new ArrayList();
            _Contact = new Contact("First Name 1", "Last Name 1");

            _Contact = new Contact("First Name 2", "Last Name 2");

            Contact[] resultList = (Contact[]) list.ToArray(typeof(Contact));

            // JSON Response
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string serializedObj = jss.Serialize(resultList);

            return serializedObj;

    /// our serializable contact class
    public class Contact
        private string _firstName;
        private string _lastName;

        public Contact() {}

        public Contact(string firstName, string lastName){
            this._firstName = firstName;
            this._lastName = lastName;

        public string firstName
            get { return this._firstName;}
            set { this._firstName = value;}

        public string lastName
            get { return this._lastName;}
            set { this._lastName = value;}

Download the .Net source code.

Running ASPX Web Services on Mac OS X using Mono.

Create a Mono Develop Solution for the source code.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.