Click here to Skip to main content
13,667,012 members
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 28 Aug 2011
Licenced CPOL

Consuming the Holidaywebservice2 with Visual Studio 2010

, 28 Aug 2011
Rate this:
Please Sign up or sign in to vote.
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[^] 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. 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. 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)

  6. Create the GetHolidays procedure for the current year. The first parameter defines the country code, in this case 1 = GreatBritain.
  7. 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. 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
    End Sub

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


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


About the Author

Jules Harcourt
Web Developer
United Kingdom United Kingdom
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

Comments and Discussions

GeneralI have error on this line. It ask for another item at the en... Pin
tinh.khau14-Oct-11 9:09
membertinh.khau14-Oct-11 9:09 
GeneralRe: Nothing more is required. Just make sure you have added the ... Pin
Jules Harcourt15-Oct-11 7:05
memberJules 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
membertinh.khau14-Oct-11 8:54 
GeneralReason for my vote of 5 Thanks! Pin
Walt Fair, Jr.28-Aug-11 8:25
subeditorWalt Fair, Jr.28-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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180810.1 | Last Updated 28 Aug 2011
Article Copyright 2011 by Jules Harcourt
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid