Subscribe

RSS Feed (xml)

ASP.NET Web Service Creation

To illustrate creating a Web service, this simple example takes a string and returns a


message.To do this, you type in the following code and save it as code01vb.asmx


<%@ WebService Language="vb" Class="codevb" %>


Imports System.Web.Services


Imports System.Text


Public Class code01vb


<WebMethod()> _


Public Function GreetCustomer(ByVal person as String) As String


Dim output As StringBuilder = New StringBuilder()


output.Append("Welcome to Cook Center Mr/Mrs.")


output.Append(Person)


output.Append(" , Hope you are enjoying our examples!!" )


GreetCustomer = output.ToString()


End Function


End Class


Now, you save this file in some Web directory.This is all that is required to create a Web


service! To see how it works, open the file in a Web browser. Microsoft provides a default


test page feature in the .NET Framework for its Web services. In that page, you will see


a GreetCustomer function. Click it, and it will take you to another page.There, you


enter some text and press Invoke. A new window opens with the output in XML


format.



In this class, you create a Web method called GreetCustomer. By adding the <WebMethod()> attribute to a method


within a .ASMX file, you create a Web service. Here, the Key attribute is <WebMethod>.


This WebMethod attribute indicates to the .NET Framework that the specified method


should be made accessible via standard Internet protocols.These Web service methods


should be defined as public, which indicates that they can be accessible from outside


parent class.This Web method has various attributes. This example uses the description


attribute.The following properties are defined for the WebMethod attribute:




  • BufferResponse-Specifies whether the response for this Web method should be buffered. By default, it is set to True.



  • CacheDuration-This specifies the number of seconds the Web method response is stored in cache.



  • Description-Specifies the user-friendly description of the publicWeb method.



  • EnableSession-Specifies whether session state is enabled for the Web method. Default setting is false.



  • MessageName-Specifies an alias name for a Web method.This MessageName attribute allows you to provide different names for overloaded methods.



  • TransactionOption-Specifies the Enterprise service transaction support for the Web method.


No comments:

Variety in the Web World