Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » Ajax » Samples » Downloads
 
Add your own
alternative version

ASP.NET 3.5, AJAX, and Web Services

, 17 Mar 2008
This article explains how to call Web Service methods using AJAX client script.
ajaxwebservice.zip
AjaxWebService
App_Code
App_Data
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Web.Script.Services;

namespace AjaxWebService
{

    [WebService(Namespace = "http://localhost:49232/AjaxWebService/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class Service : System.Web.Services.WebService
    {
        string myXmlData = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
                <Book>
                    <Title>Programming ASP.NET 3.5, AJAX and Web Services</Title>
                </Book>";
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod]
        public string getNextBackupDate(int months)
        {
            return DateTime.Now.AddMonths(months).ToShortDateString();
        }
        
        [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
        [WebMethod]
        public XmlDocument GetBookTitle()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(myXmlData);
            return xmlDoc;
        }
       
        [ScriptMethod(UseHttpGet = true)]
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello, world";
        }

    }
}

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)

About the Author

Balamurali Balaji
Founder BB Systems CIT-GPNP
India India
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 18 Mar 2008
Article Copyright 2008 by Balamurali Balaji
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid