Key Notes To ASP.NET Web Services

Introduction

Web services used for enabling an application to invoke a method of another application.

These applications can be on the same computer or different computers. Web services use protocols like HTTP, XML and SOAP.

Description

Web services used for enabling an application to invoke a method of another application.

These applications can be on the same computer or different computers. Web services use protocols like HTTP, XML and SOAP. Since these are open and well known protocols, applications built on any platform can interoperate with web services. For example, a PHP application can interoperate with a web service built using .NET. Similarly a web service built using different platform can be consumed by a .NET application.

Hyper Text Transfer Protocol (HTTP) is the protocol widely used by web services to send and receive messages.
The messaging protocol is SOAP. SOAP stands for Simple Object Access Protocol. SOAP messages are in XML format. Web Services have .asmx extension. For this reason web services are also often called as ASMX web services.

Top 11 Notes While Write Code For Web Services
  1. To use asp.net session object in a web service, the web service class must inherit from System.Web.Services.WebService class and EnableSession property of WebMethod attribute must be set to true. Hyper Text Transfer Protocol (HTTP) is the protocol widely used by web services to send and receive messages.

    The messaging protocol is SOAP. SOAP stands for Simple Object Access Protocol. SOAP messages are in XML format.

  2. Notice that a web service is a class that is decorated with [WebService] attribute and inherits from System.Web.Services.WebService base class. The [WebService] attribute tells that this class contains the code for a web service. Web Service Namespace is used to uniquely identify your web service on the internet from other services that are already there on the Web. Web Service Namespace can be any string, but it is common to give it a company's internet domain name as they are usually unique.

  3. To allow a web service to be called from Javascript , using ASP.NET AJAX, then decorate the web service class with [System.Web.Script.Services.ScriptService] attribute. 

  4. Web Method attribute used to specify description for the web service method.

  5. BufferResponse is a boolean property. Default is true. When this property is true, the response of the XML Web service method is not returned to the client until either the response is completely serialized or the buffer is full. On the other hand, when this property is false, the response of the XML Web service method is returned to the client as it is being serialized. In general, set BufferResponse to false, only when the XML Web service method returns large amounts of data. 

  6. CacheDuration is the property, if you want to cache the results of a web service method. This is an integer property, and specifies the number of seconds that the response should be cached. The response is cached for each unique parameter. 

  7. Web Methods in a web service can also be overloaded based on the number of parameters. Method overloading possible in web services by using MessageName property of WebMethod attribute. MessageName property is used to uniquely identify the individual XML Web service methods.

  8. Call the web service using ASP.NET AJAX, which allows partial page post back. With partial page post back, only specific portion of the page is updated without reloading the entire page.

  9. For smaller amounts of data, web service performance is better when BufferResponse is set to true.

  10. In Web.Config file When allowCookies attribute is set to true, the client application accepts the cookie returned from the ASMX web service, and copies it into all future requests that are made to the web service. This ensures that the same session is maintained between the client and the web service.

  11. To use asp.net session object in a web service, the web service class must inherit from System.Web.Services.WebService class and EnableSession property of WebMethod attribute must be set to true.
Next Recommended Reading Call a Web Service from a Web Form