-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: Nasha
Message 1 in Discussion

 

Hey Group,<o:p></o:p> 
 <o:p></o:p> 
After creating our basic web service yesterday we will look into the web method 
properties and supported data types.<o:p></o:p> 
 <o:p></o:p> 
Well Whenever we create a web service all those methods of the web service 
which we want to be web-callable have to be marked with the web method 
attribute and should have a public access modifier. Web Method Attribute is 
basically used to make a method web callable.<o:p></o:p> 
 <o:p></o:p> 
WebMethod attribute has the following properties like :-<o:p></o:p> 
 <o:p></o:p>    Description<o:p></o:p>  TransactionOption<o:p></o:p>    
CacheDuration<o:p></o:p>        BuffferResponse<o:p></o:p>      
EnableSession<o:p></o:p>        MessageName<o:p></o:p> 
 <o:p></o:p> 
Description :- It is used for commenting the web method. The description that 
is added here is included in WSDL. Add the <o:p></o:p> 
webmethod description property above any method as shown below. When you call 
the webservice from a browser you view the web service.<o:p></o:p> 
 <o:p></o:p> 
 e.g. [WebMethod(Description = "My WebMethod Description comes 
here")]<o:p></o:p> 
 <o:p></o:p> 
Enable Session :- WebServices are a type of ASP.NET applications hence you can 
access your ASP.NET application Session from your webservice. By default the 
session is disabled i.e. set to false. You can enable it by setting its value 
to true.<o:p></o:p> 
 <o:p></o:p> 
 e.g. [WebMethod(EnableSession ="true")]<o:p></o:p> 
 <o:p></o:p> 
Message Name :- Message Name property is used give an alias to a method name. 
This is esp. useful when you are using overloaded methods.<o:p></o:p> 
 <o:p></o:p> 
e.g. Yesterday we created  3 method in our webservice for cos,sin and tan which 
took double as an input parameter. Today we will create their overloads that 
will take int as an input parameter <o:p></o:p> 
 <o:p></o:p> 
  [WebMethod]
  public double Tan(int angel)
  {
   return System.Math.Tan(angel);
  }
  [WebMethod]
  public double Sine(int angel)
  {
   return System.Math.Sin(angel);
  }
  [WebMethod]
  public double CoSine(int angel)
  {
   return System.Math.Cos(angel);
  }<o:p></o:p> 
 <o:p></o:p> 
If you compile this code it will compile successfully. It is on execution that 
you we view the below error message<o:p></o:p> 
 <o:p></o:p> 
Error Message: Both Double Tan(Int32) and Double Tan(Double) use the message 
name 'Tan'. Use the MessageName property of the WebMethod custom attribute to 
specify unique message names for the methods. <o:p></o:p> 
 <o:p></o:p> 
Web service needs to identify each method uniquely hence we will give alias to 
the methods by setting the MessageName property.<o:p></o:p> 
 <o:p></o:p> 
 e.g. [WebMethod(MessageName = "SinInt")]
       [WebMethod(MessageName = "CosInt")]
       [WebMethod(MessageName = "TanInt")]<o:p></o:p> 
 <o:p></o:p> 
TransactionOption : - If our web service is a part if any COM/MTS transaction 
application then we can enable the Transaction Option of the webservice thus 
making it a part of the  2 phase commit protocol of MTS.<o:p></o:p> 
 <o:p></o:p> 
 e.g.     [WebMethod(TransactionOption = "Supported")]<o:p></o:p> 
 <o:p></o:p> 
The dafault is same as COM/MTS transactions i.e. Required.<o:p></o:p> 
 <o:p></o:p> 
CacheDuration :- Like any other ASP.NET applications WebServices also support 
output caching. Output caching gives a performance boost coz the same request 
is not executed repeatedly instead the result is return from the cache itself. 
This feature is <o:p></o:p> 
esp. useful when you are retrieving chunks of data from the database for 
listing and other purposes. But caching should preferably used with only those 
methods where we know that the data will not change frequently.<o:p></o:p> 
 <o:p></o:p> 
 e.g.     [WebMethod(CacheDuration = "180")]  
 
This means the output of this method will be cached for  seconds.<o:p></o:p> 
 <o:p></o:p> 
BuffferResponse :- We all are familiar with the buffering property rite from 
our ASP days where used Response.Buffer = true so that <o:p></o:p> 
the response is only sent when the Response for the request is completely 
generated or when the buffer is full. WebServices also use the same logic. If 
we want our response to be sent across only after its complete processing is 
done we need to buffer our response by setting its property to true.<o:p></o:p> 
 <o:p></o:p> 
 e.g.     [WebMethod(BufferResponse = "true")]  <o:p></o:p> 
 <o:p></o:p> 
By default it is set to true.<o:p></o:p> 
 <o:p></o:p> 
These properties were webmethod properties. We also have some web service 
properties like<o:p></o:p> 
 <o:p></o:p>    Description.<o:p></o:p>         Name<o:p></o:p>         
NameSpace
 <o:p></o:p> 
Description :- This is same as web method property. It is used to comment web 
service and give it a description that is included in WSDL.<o:p></o:p> 
 <o:p></o:p> 
 e.g. [WebService(Description = "My WebService Description comes here")]
  public class MyService : System.Web.Services.WebService<o:p></o:p> 
  {
Name :- By default the name of the class is used as the service name but incase 
we want to give a different service name which will to exposed to our clients 
and in WSDL we can set the Name property. This property will override the 
default value i.e. the class name. <o:p></o:p> 
 <o:p></o:p> 
 e.g. [WebService(Name = "MyNewName")]
  public class MyService : System.Web.Services.WebService
  {<o:p></o:p> 
 <o:p></o:p> 
NameSpace :-  The default name space is http://tempuri.org. You can change this 
to http://localhost/MyWebServices. You should set namespace to any unique 
value.<o:p></o:p> 
 <o:p></o:p> 
 e.g. [WebService(Namespace = "http://localhost/MyWebServices";)]
  public class MyService : System.Web.Services.WebService
  {<o:p></o:p> 
 <o:p></o:p> 
-- Please post your queries and comments for my articles in the user group for 
the benefit of all. I hope this step from my end is helpful to all of us.

Regards,

Namratha (Nasha) <o:p></o:p> 
 <o:p></o:p>

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to