Figure 3

Figure 3 TimeService.asmx
<%@ WebService Language="VB" Class="TimeService"%>

' The previous header line tells ASP.NET that this file contains
' a Web Service written in the Visual Basic language
' and that the name of the class providing that service
' is TimeService

' Import the namespaces (think of them as references)
' required for a web service

Imports System
Imports System.Web.Services

' Declare a new class for our new service. It must inherit
' from the system-provided base class WebService

Public Class TimeService : Inherits WebService

' Place our functions in the class. 
' Mark them as WebMethods

   Public Function <WebMethod()> GetTime (ShowSeconds as Boolean) 
                                 As String

' Perform the business logic of our function
' Find current time, format as requested, and
' return the string

      Dim dt as DateTime

       If (ShowSeconds = TRUE) Then
         GetTime = dt.Now.ToLongTimeString
        GetTime = dt.Now.ToShortTimeString

   End Function

End Class
Figure 6 Excerpts from Sample Web Service SDL Contract
<?xml version="1.0"?>
<serviceDescription name="TimeService">
       <requestResponse name="GetTime" 
                  <param name="ShowSeconds"/>
                  <mimeXml ref="s1:string"/>

<!— descriptions of other protocols, httpget and soap, go here —>

<element name="GetTime">
              <element name="ShowSeconds" type="boolean"/>
     <element name="GetTimeResult">
                <element name="result" type="string" nullable="true"/>
Figure 8 HTTP POST Support
      <requestResponse name="GetTime" href="http://localhost/
            <input name="ShowSeconds"/>
          <mimeXml ref="s1:string"/>
Figure 10 HTML Code for the Form
<form METHOD="POST" ACTION="http://localhost/aspxtimedemo/
  <p>Would you like to show the seconds digits ?</p>
    <p><input TYPE="RADIO" NAME="ShowSeconds" VALUE="True" CHECKED> True 
        <input TYPE="RADIO" NAME="ShowSeconds" VALUE="False"> False<br>
  <input TYPE="SUBMIT" VALUE="Submit Form"> <input TYPE="RESET"
         VALUE="Reset Form">
Figure 11 Portion of SDL File
<soap xmlns="urn:schemas-xmlsoap-org:soap-sdl-2000-01-25">
        <address uri="http://localhost/aspxtimedemo/timeservice.asmx"/>
      <requestResponse name="GetTime" soapAction="     
        <request ref="s0:GetTime"/>
        <response ref="s0:GetTimeResult"/>
Figure 13 SOAP Proxy Class Generated by WebServiceUtil
' <autogenerated>
'     This class was generated by a tool.
'     Runtime Version: 2000.14.1812.10
'     Changes to this file may cause incorrect behavior 
'     and will be lost if the code is regenerated.
' </autogenerated>

Imports System.Xml.Serialization
Imports System.Web.Services.Protocols
Imports System.Web.Services

Public Class TimeService
    Inherits System.Web.Services.Protocols.SoapClientProtocol
    Public Sub New()
        Me.Path = "http://localhost/aspxtimedemo/timeservice.asmx"
    End Sub
    Public Function 
        "<System.Web.Services.Protocols.SoapMethodAttribute(" _ &
        " GetTime"), _ &      
        "System.Web.Services.Protocols.SoapParameterAttribute _
        ("showSeconds", ElementName:="ShowSeconds")> _
        GetTime(ByVal showSeconds As Boolean) As String
        Dim results As Object() = Me.Invoke(" _
        GetTime", New Object() {showSeconds})

        Return CType(results(0), String)
    End Function
    Public Function BeginGetTime(ByVal showSeconds As Boolean, _
        ByVal callback As System.AsyncCallback, _
        ByVal asyncState As Object) As System.IAsyncResult
        return Me.BeginInvoke("GetTime", New Object() {showSeconds},
                              callback, asyncState)
    End Function

    Public Function EndGetTime(ByVal asyncResult As System.IAsyncResult) 
                               As String
        Dim results As Object() = Me.EndInvoke(asyncResult)
        return CType(results(0),String)
    End Function
End Class
Figure 14 Accessing the SOAP Proxy
Public Class Form1
    Inherits System.WinForms.Form

    ' User clicked GetTime button

Protected Sub btnGetTimeSynch_Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs)

    ' Create new object of proxy class

    Dim ThisTimeServiceProxy As New TimeService()

    ' Set the Path property to that specified by the user

    ThisTimeServiceProxy.Path = TextBox2.Text

    ' Actually call the function. Put returned result into text box 
    ' for user to see

            TextBox1.Text = 
End Sub

' Commence the asynchronous call to get the time

Dim AsyncTimeServiceProxy As TimeService
Dim AsyncResult As IAsyncResult

Protected Sub btn_BeginGetTimeAsync_Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs)
    AsyncTimeServiceProxy = New TimeService
    AsyncResult = AsyncTimeServiceProxy.BeginGetTime(CheckBox1.Checked, 
                  Nothing, Nothing)
End Sub

' Check to see if the operation has completed

Protected Sub btnPollForComplete_Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs)
    If (AsyncResult.IsCompleted) Then
        MsgBox("Not Complete")
        End If
End Sub

' Harvest the results of the asynchronous call for getting the time

Protected Sub btnEndGetTimeAsync_Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs)
    TextBox1.text = AsyncTimeServiceProxy.EndGetTime(AsyncResult)
    AsyncTimeServiceProxy = Nothing
End Sub

End Class
Figure 18 Web Service Code File
Imports System
Imports System.Collections
Imports System.Core
Imports System.ComponentModel
Imports System.Configuration
Imports System.Web.Services
Imports System.Diagnostics
Imports System.Data

Namespace VS7DemoTimeService

    Public Class WebService1
        Inherits System.Web.Services.WebService

        Public Function  <WebMethod()> GetTime(ByVal ShowSeconds As 
                                               Boolean) As String

            ' Perform the business logic of our function
            ' Find current time, format as requested, and
            ' return the string

            Dim dt As DateTime
            Dim out As String
            out = "The time is now: "
            If (ShowSeconds = True) Then
                out = out + dt.Now.ToLongTimeString
                out = out + dt.Now.ToShortTimeString
            End If

            ' If CallersToday application property is nothing, then it's
            ' the first time
            ' we've run this app. Put in a value of '1', because the caller 
            ' counts

            If (Application("TotalCallers") = Nothing) Then
                Application("TotalCallers") = 1
                ' Update application state to tell user how many callers 
                ' have asked
                Application("TotalCallers") =  
                Convert.ToInt32(Application("TotalCallers")) + 1
            End If

            ' Format string to tell caller about it

            out = out + "and you're the "
            out = out + Convert.ToString(Application("TotalCallers"))
            out = out + "th person to ask me"

            ' If LastTimeYouCalled property is nothing, then tell use

            If (Session("LastTimeThisGuyAsked") = Nothing) Then
                out = out + ", but you haven't asked before"
                out = out + " and you last asked at " + _
            End If
            Session("LastTimeThisGuyAsked") = dt.Now.ToLongTimeString

            GetTime = out
        End Function

    End Class

End Namespace