O'Reilly logo

Programming Visual Basic .NET, Second Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a Web Service

To illustrate the techniques used to implement a web service in Visual Basic .NET using the services classes of the .NET Framework, you will build a simple calculator and then make use of its functions over the Web.

Begin by specifying the web service. To do so, define a class that inherits from System.Web.Services.WebService. The easiest way to create this class is to open Visual Studio and create a new ASP.NET Web Service project. The default name that Visual Studio provides is WebService1, but you might want to choose something more appropriate.

Visual Studio .NET creates a skeleton web service and even provides a .NET Web Service example method for you to replace with your own code, as shown in Example 16-1.

Example 16-1. Skeleton web class generated by Visual Studio .NET

Option Strict On Imports System Imports System.Web.Services <WebService(Namespace := "http://tempuri.org/")> _ Public Class Service1 Inherits System.Web.Services.WebService #Region " Web Services Designer Generated Code " Public Sub New( ) MyBase.New( ) 'This call is required by the Web Services Designer. InitializeComponent( ) 'Add your own initialization code after the InitializeComponent( ) call End Sub 'Required by the Web Services Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Web Services Designer 'It can be modified using the Web Services Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required