Page 230 - DCAP312_WEB_TECHNOLOGIES_II
P. 230

Web Technologies-II



                   Notes         From the above code, we see that service is the class that contains all the code that implements the
                                 web service methods. This is actually the name of the WebService; it is named after the class and
                                 not after the project. The .vb and .asmx files together form the Code model for the web services.
                                 As we have known a web service is basically a class that sits on the server. Building a Web
                                 Service with Visual Studio is as simple as writing a class. The class inherits from System.Web.
                                 Services and this base class includes all that is necessary to make the functions (methods) of the
                                 class available on the Web. The Web Service class belongs to the System.Web.Services namespace.
                                 This class provides direct access to built-in ASP.NET objects, such as Application and Session.
                                 If an application does not require these objects, we can create a Web service without deriving
                                 it from the Web Service class. So, Note that deriving from a web service base class is optional.
                                 Examining the Web Service Files
                                           Service.asmx file.
                                           <%@ WebService Language= “vb” CodeBehind= “~/App_Code/Service.
                                           vb” Class= “Service” %>
                                 In the above line of code, a WebService is the web processing directive that specifies a class
                                 name; here service for a web service and the language used to create the web service is visual
                                 basic. Service.vb file. Explanation of the WebService attributes. The WebService attribute is an
                                 optional attribute that can be used to provide additional information about the Web service. We
                                 can also use the WebService attribute to provide a unique namespace for the web service. This
                                 namespace can be used by client applications to resolve conflicts that may arise due to different
                                 Web services having methods with the same name. The Webservice attribute can be provided
                                 before the Web service class declarations as shown below.
                                           <WebService (Namespace:=http://vkinfotek.com/services,
                                           Description: = “This Web service contains a method for displaying Hello
                                           world string”)>
                                           Public Class Service
                                           Inherits System.Web.Services.WebService
                                           End class

                                 The description of the Web service appears in the browser window when we try to access the
                                 web service directly by providing the path. The WebMethod Attribute. The methods that we
                                 want to expose to web service are marked with WebMethod attribute. The WebMethod attribute
                                 enables us to call remotely, the web service methods over the internet. The syntax for applying
                                 the WebMethod attribute to a method is  given below. Syntax for applying the WebMethod
                                 attribute to a method is given below.
                                       <WebMethod ()> Public Function functionname (Parameter list) As ReturnType
                                 The methods of this class do not return an HTML page; instead, they return one or more values,
                                 packaged as XML documents. Basically, if you can write a function, you can write a web method;
                                 it is that simple. The difference between a class and a WebService class is that the members of
                                 the WebService can be called remotely. VB.NET uses less than and greater than symbols to the
                                 attribute to appear on the line before the function definition.
                                 From the above code, we note that class name is Service and method is Hello World. If we
                                 want to change its name, we must rename the Service item in the Solution Explorer’s window,
                                 as well as the name of the class in the code. Note that we can also create methods without
                                 preceding them with the WebMethod attribute.  However, these methods cannot be used to
                                 expose some functionality to applications. They can only be used by the other methods within
                                 the Web service class.




        224                               LOVELY PROFESSIONAL UNIVERSITY
   225   226   227   228   229   230   231   232   233   234   235