Page 229 - DCAP312_WEB_TECHNOLOGIES_II
P. 229

Unit 11: Web Services in Visual Studio .NET



                                  Figure 11.1: Creating new Web Service                           Notes



























            A new virtual directory - Hello Service - will be created on your computer's Web server. This
            action also creates two files called Service.asmx and service.vb. Please note that Visual Studio
            creates the entry point file with .asmx extension and the other code behind file with .vb extension.
            These files are automatically added to the project, which we can see in a solution explorer. The
            service.asmx amd service.vb files represent a single web service. Web Services do not have a
            visible interface and so, the design interface is empty. When we open the Service.asmx file, only
            the following code is seen.
                     <%@ WebService Language= “vb” CodeBehind= “~/App_Code/Service.
                     vb” Class= “Service” %>
            The service.asmx file serves as the entry point into the web service. The other file, service.vb,
            is the code-behind file for the web service. We can write the functionality of the web service
            in this file. The code-behind file imports the System.Web.Services namespace. This namespace
            contains the classes that are required to build and use Web services. We can view this file by
            switching to the code view for the service.asmx file.

            Note that a single project can contain multiple Web Services, each web service implemented by
            a different class. If we open the service.vb code-behind page, we can see the default code which
            is created by vs.NET automatically, as listed below.
                     Import System. Web
                     Import System.Web.Services
                     Import System.Web.Services. Protocols
                     <WebService (Namespace:= “http://tempuri.org/”)>
                     <WebServiceBinding (Conforms To: =WsiProfiles.BasicProfile1_1)>
                     <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerted ()>_
                     Public Class Service
                     Inherits System.Web.Services. WebService
                     <WebMethod ()>
                     Public Function Hello World () As String
                     Return “Hello World”
                     End Function
                     End Class
                                             LOVELY PROFESSIONAL UNIVERSITY                                   223
   224   225   226   227   228   229   230   231   232   233   234