Hi I Have a web method on the Server. Below Is My Web Method.
ASP.NET Syntax (Toggle Plain Text)

[WebMethod]
    public string GetAge(int year, int month, int day)
    {
        DateTime birthDate = new DateTime(year, month, day);
        long age = new DateTime(DateTime.Now.Ticks - birthDate.Ticks).Year - 1;
        return "You are " + age.ToString() + " years old.";
    }

    //This method caches the datetime for 4 seconds. 
    //also a simple cache implementation. 
    private const int CacheTime = 4; // seconds
    [WebMethod(CacheDuration = CacheTime,
    Description = "As simple as it gets - the ubiquitous Get Date Time.")]
    public string GetDateTime()
    {
        return DateTime.Now.ToString();
    }

Now I Want To run This Webmethod Through HTML Page which is on my system.

This Is my Code. But I am not getting the application run.

Below I have given my code.

ASP.NET Syntax (Toggle Plain Text)

<html>
<head>
    <title>UseSwap</title>
        <script language="JavaScript">
            function InitializeService()
            {
                service.useService("http://localhost:1394/MyWebService.asmx?wsdl",  "GetAgeService");

               // [url]http://localhost:3330/EIMBA/ServiceEIMBA.asmx[/url]
            }
            var StrYear, StrMonth, StrDay;
            function GetAge()
            {
                StrYear = document.DemoForm.StringYear.value;
                StrMonth = document.DemoForm.StringMonth.value;
                StrDay = document.DemoForm.StringDay.value; 

                service.GetAgeService.callService("GetAge", StrYear, StrMonth, StrDay);
            }
            function ShowResult()
            {
                alert(event.result.value);
            }
    </script>
</head>
    <body onload="InitializeService()"  id="service" style="behavior:url(webservice.htc)"  onresult="ShowResult()">
        <form name="DemoForm">
            Year : <input type="text" name="StringYear"/><br />
            Month : <input type="text" name="StringMonth"/><br />
            Day : <input type="text" name="StringDay"/><br /> 
            <button onclick="GetAge()">Get Age</button><br />
        </form>
    </body>
</html>

Can any one tell me how to execute the webservice from my HTML code. any changes needed from my HTML Code.

Please wrap code in code-tag.
We will understando more your problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.