moone009 0 Junior Poster in Training

I found this example online and cannot figure out why it will not work. I was wondering if anyone could help me figure out why this code does not work ive spend a few hours tinkering with it and no luck. I learn best by example and just basically need one simple example of a working html page using javascript before I build some webservices to pull mssql data.

all help is appreciated and I am using visual studio 2008

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function GetAge(ByVal year As Integer, ByVal month As Integer, ByVal day As Integer) As String
        Dim birthDate As New DateTime(year, month, day)
        Dim age As Long = New DateTime(DateTime.Now.Ticks - birthDate.Ticks).Year - 1
        Return "You are " & age.ToString() & " years old."
    End Function
End Class




<html>
<head>
    <title>UseSwap</title>
        <script language="JavaScript">
            function InitializeService()
            {
                service.useService("http://localhost:63649/Service1.asmx?wsdl",  "Service1");
            }
            var StrYear, StrMonth, StrDay;
            function GetAge()
            {
                StrYear = document.DemoForm.StringYear.value;
                StrMonth = document.DemoForm.StringMonth.value;
                StrDay = document.DemoForm.StringDay.value; 

                service.Service1.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>
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.