Click here to Skip to main content
15,880,956 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Consuming the Holidaywebservice2 with Visual Studio 2010

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
28 Aug 2011CPOL1 min read 18.3K   2   4
How to use the excellent Holiday web service in VB.NET using VS 2010.

The documentation provided on the web service site[^] is patchy to say the least, especially for ASP.NET. It only directs you to the generic MSDN web service walkthrough page. After a few fruitless hours of searching the internet for the best way to use the new HolidayWebService2[^], I managed to solve it myself.


For my purposes, marking a public holiday on a calendar object on a web form, I found this to be the best method. In this example, I am loading a local array from the published one for all the holidays in the current year.



  1. Add the web service in VS 2010 by pasting http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx[^] into the web service dialog.
  2. In your code behind page, add a one dimensional array to hold the data and an object for the service in your page declarations. Note the use of the web service to define the array type.
  3. VB
    Public Class CalendarPage
        Inherits System.Web.UI.Page
        Public arrHolidays() As com.holidaywebservice.www.Holiday
        Dim wsHolidays As New com.holidaywebservice.www.HolidayService2

  4. In your Page_Load event, add the code to load the data from the web service.
  5. VB
    Protected Sub Page_Load(ByVal sender As Object, _
           ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            calCalendar.VisibleDate = _
                DateSerial(Year(DateTime.Today), Month(DateTime.Today), 1)
            GetHolidays(Year(DateTime.Today))
            .

  6. Create the GetHolidays procedure for the current year. The first parameter defines the country code, in this case 1 = GreatBritain.
  7. VB
    Private Sub GetHolidays(ByVal intYr As Integer)
        arrHolidays = wsHolidays.GetHolidaysForYear(1, intYr)
    End Sub

  8. Finally you can use the array in the day render code of the calendar control to put a border round the holiday day and set a tool tip to display its name, which is held in the Descriptor element. BankHoliday = 0 means that it is a 'Recognized' public holiday, 1 is used for notable dates such as Valentine's day, which is not a holiday.
  9. VB
    Private Sub calCalendar_DayRender(ByVal sender As Object, _
            ByVal e As WebControls.DayRenderEventArgs) Handles calCalendar.DayRender
        Dim nextDate As DateTime
        e.Cell.BorderWidth = 3
        e.Cell.BorderColor = Drawing.Color.White
        For Each objHoliday As com.holidaywebservice.www.Holiday In arrHolidays
            If objHoliday.Date = e.Day.Date And objHoliday.BankHoliday = 0 Then
                e.Cell.BorderColor = Drawing.Color.Black
                e.Cell.ToolTip = String.Concat(e.Cell.ToolTip, " ", objHoliday.Descriptor)
            End If
        Next
    End Sub


I hope this proves useful to anyone else using this web service.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralI have error on this line. It ask for another item at the en... Pin
tinh.khau14-Oct-11 9:09
tinh.khau14-Oct-11 9:09 
GeneralRe: Nothing more is required. Just make sure you have added the ... Pin
Jules Harcourt15-Oct-11 7:05
Jules Harcourt15-Oct-11 7:05 
GeneralI am new to Web Service. Could you explain how you name the ... Pin
tinh.khau14-Oct-11 8:54
tinh.khau14-Oct-11 8:54 
GeneralReason for my vote of 5 Thanks! Pin
Dr.Walt Fair, PE28-Aug-11 8:25
professionalDr.Walt Fair, PE28-Aug-11 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.