Pages

Men

rh

6/23/2012

Properties of Web Method in Web Service in Asp.Net

Properties of Web Method in Web Service:-
  • The Buffer Response
  • The Cache Duration
  • The Description
  • The Enable Session
  • The Message Name
  • The Transaction Option

The Buffer Response:-
  • It enables buffering response for a Web method.
  • The Buffer Response might be True or False. When set to 'True' then  default setting is true.
  • Asp.Net buffers the entire response before sending it down to the client.
  • The Buffer Response set to 'False' asp.net buffers the response in the chunks of 16 KB.
  • If we don't want  entire control of the response in memory at once then we can set buffer response to false.

Example:-
public class Service1: System.Web.Service.WebService
{
   [WebMothod (Buffer Response :=False)]
     public void Getdata()
    {  
      . . . . . .
    }
}

The Cache Duration:-
  • It enables caching of the results for a web method.
  • Syntax:- [WebMethod(CacheDuration:=Property Value)]
  • Here the property value is number of seconds the response should be held in the cache.
  • The Dafault is '0' which means the response is not cached.
  • Asp.Net will cache the results for each unique parameter set.

Example:-

[WebMothod (Cache Duration :=60)]

public double ConvertTemp(double dfHeat)
{
return ((dfHeat -32) * 5 )% 9);
}

Enable Session:-
  • It enables the session state for Web Service Method.
  • Session State is not needed for web service method, the disabling it improve the performance.
  • The default enable session is  "False"

Example:-
[WebMethod (EnableSession:= False)]
public int SessionHitCounter()
{
   if(Session["HitCount"] == "")
   {
     Session["HitCount"] = 1;
   }
   else
   {
     Session["HitCount"] = CInt("HitCount") + 1;
    Return CINT("HitCount");
  }
}

Message Name:-
  • It enables the WebService to iuniquly identify  overloaded method using an Alias.
  • The default value is method name.
  • When specifying the method name, the resulting SOAP message will reflect this name instead of the actual method name.

Example:-
[WebMethod (MessageName:= "Add Double")]
public double add1(double dValue, Double Dvalue1)
{
  return dValue1 + dValue2;
}

Transaction Options:- 
It Enables to patispate as the root element.
It has the following values.
  • Disabled
  • Not Supported
  • Supported
  • Required
  • Required New

Disabled:- It indicates web service method doe not run with the transaction.
Example: [WebMethod (Transactionoption = Transactionoption.Disabled)

NotSupported: It indicates the the web service method doe not run with in  the scope of a transaction.
Example: [WebMethod (Transactionoption = Transactionoption.Notsupported)

Supported: runs with the scope of a transaction
Example: [WebMethod (Transactionoption = Transactionoption.Supported)

Required: Indicates that the Web Service requires a transaction.
Example: [WebMethod (Transactionoption = Transactionoption.Required)
Required New: Indicates that the Web Service requires new transaction.
Example: [WebMethod (Transactionoption = Transactionoption.RequiredNew)

No comments :

Post a Comment