| Author: Athira Appukuttan 19 Aug 2008 | Member Level: Diamond | Rating: Points: 6 |
Hi..
Web Services support both synchronous and asynchronous communication between the client and the server that hosts the Web Service. Under synchronous communication, the client sends a request to the server and waits for the response. This prevents the client from performing other operations while waiting for the results. On the other hand, in asynchronous communication, the client continues processing other tasks as it waits for a response. The client responds to the result of the service request when it becomes available. The Web Service Attribute The Web Service Attribute is a member of the System.Web.Services namespace. This we can use to let the clients know where to find information about a Web Service. There are three properties of the Web Service attribute. They are as follows:
1. Description
2. Namespace
3. Name
Description
The Description property is used to provide a brief description of the functionality of the class. We can write the same as specified in Listing 2.
Listing 2
[WebService(Description="This class contains methods for working with Addition of numbers and Population of DataSet")]Namespace
The Namespace property sets the XML namespace for the service. Generally we use an URL. It does not have to be an actual URL; it can be any string value. The idea is that it should be unique. It is common practice to use URL because a URL is always unique.
Name
When the WSDL is generated for an ASP.NET Web Service, the name of the class is used for the service name within the WSDL. When a proxy uses the WSDL and builds a proxy class, the name of the class generated corresponds to the name value of service. This property allows overriding the default value. The Web Method Attribute A Web Service class can contain any number of WebMethods that are accessible across the HTTP wire. Like the Web Service attribute, WebMethod can also contain some properties which are described in this section.
CacheDuration
CacheDuration specifies the number of seconds that the response should be held in the system’s cache. By default, the caching is disabled. Putting an XML Web Service’s response in the cache increases the Web service’s performance. We can write the same as specified in Listing 3
Listing 3
[WebMethod(CacheDuration=30)]BufferResponse
Buffering allows the server to buffer the output from the response of XML Web Service and transmit it only once the response is completely buffered. By default, this property is set to true. If we make the property to false, the response is sent to the client as it is constructed on the server.
Description
The description property is used to provide a brief description to the WebMethod and the description becomes part of the service description (WSDL) document.
EnableSession
EnableSession property enables session state for a particular WebMethod if we set the property to true. The default setting is false.
MessageName
MessageName property is required to uniquely identify polymorphic methods within a class. In case of working with overloaded WebMethods this property is a required one.
TransactionOption
By default, transactions are disabled. If we decide to use .NET transactions, our WebMethod will be able to participate only as the root object in a transaction. This means that our WebMethod may call other transaction-enabled objects, but may not itself be called as part of a transaction started by another object. This limitation is due to the stateless nature of the HTTP protocol. As a result, the Required and RequiresNew values for TransactionOption are equivalent (and both declare a RequiresNew method that will start a new transaction). Disabled, NotSupported, and Supported are all disable transactions for the web method despite what their names imply. Building a Web Service Building a Web Service with Visual Studio.Net involves creating a new Web Services project and adding methods and properties to a Web Services class form (i.e. an .asmx file). This section builds a Web Service with Visual Studio.Net. Followings are the steps in short to create an .asmx file.
1. Start Visual Studio .NET
2. Select New Project
3. Select Visual C# Project as Project Type and Asp.Net Web Service as Template
A solution will be generated. In solution explorer there will be an asmx file.
The following code we should write in .asmx file as specified in Listing 4.
Listing 4
[WebMethod] public string Add(int a, int b) { return Convert.ToString(a + b); } [WebMethod] public DataSet Populate(string con, string sql) { DataSet DS=new DataSet(); SqlConnection conn=new SqlConnection(con); SqlDataAdapter DA=new SqlDataAdapter(sql, conn); DA.Fill(DS); return DS; }In the above code there are two methods in Web Service. These methods are known as the WebMethods. The Add WebMethod returns the sum of two integer value as string. Populate web method takes two string type arguments, one for connection string and the other for sql query, and returns a DataSet object.
|
| Author: UltimateRengan 19 Aug 2008 | Member Level: Diamond | Rating: Points: 4 |
hi, http://www.15seconds.com/issue/031124.htm http://www.computerworld.com/developmenttopics/development/story/0,10801,79698,00.html http://www.stardeveloper.com/articles/display.html?article=2001121901&page=1 http://people.apache.org/~jaliya/AsynchronousWS/Asynchronous%20Web%20Wervices_Apache.ppt
i hope this may help u
|
| Author: ashok 21 Aug 2008 | Member Level: Bronze | Rating: Points: 3 |
http://www.codeproject.com/KB/cs/webservice.aspx
http://www.codeproject.com/KB/webservices/aspwebsvr.aspx
hope this examples will guide u for better understanding
|