Web Service
- Web Services are used to expose data and functionality in a distributed environment.
- The data exposed can be as simple as a list of product categories or as complex as a multileveled dataset containing a complete customer purchase history.
- Web Services are XML based, and distributed applications access them over the Internet using a communications protocol such as Simple Object Access Protocol (SOAP).
- Because the data returned by a Web Service is in the form of a standardized XML message, applications residing on various platforms can access the same Web Services.
- The primary difference between a Web Service application and an ASP.NET application is the interface. An XML Web Service relies on help pages and discovery files to interface with its users.
- The user of a Web Service is typically another application, so no traditional user interface is necessary.
Web Service optimization
- Call Web Methods Asynchronously
- Use ExecuteXmlReader instead of DataSet
- Use Compression
- Using SOAP Extensions
- Use One-Way Method
- Using Transactions in Web Services
- SOAP, HTTP GET, HTTP Post
- Create instances in advance to preload all the referenced assemblies at the very beginning
- Use pre-authentication
- Edit IIS custom error messages
Call Web Methods Asynchronously
- A web-method is invoked asynchronously, in other words an invoked member will perform its work on a different thread and after all the work is done, this member must notify the main thread and, optionally, pass the return values to it.
- This seriously increases performance. If a complicated and slow web method is executed in a separate thread, then the main application can proceed to perform its tasks without waiting for a web method to complete.
- To call a Web method asynchronously, you have the following choices:
Create a new thread and call the method from there.
Create a delegate object that matches the Web method signature and call it from there.
Use ExecuteXmlReader instead of DataSet
- Using ExecuteXmlReader, you can return an XmlDocument object or a string from a Web Service.
- You can fully control the response of a WebMethod.
String sqlString = "SELECT CustomerID, CompanyName FROM Customers For XML AUTO";
rdr = command.ExecuteXmlReader();
rdr.Read();
while (rdr.ReadState != System.Xml.ReadState.EndOfFile)
{
ret += rdr.ReadOuterXml();
}
Use Compression
- Compress the XML-traffic between the client and the server using the SOAPExtensions mechanism and any compression algorithm.
- You can use a ZIP-compression for you data. There are many of open-source compression libraries for C#.
- You can use a free library called SharpZipLib to compress your web methods.
- Adding a compression to your webservice is very easy: include the downloaded project into your solution, reference it in your webservice, and mark your web methods with [CompressionExtension] in the proxy-class code.
Using SOAP Extensions
- Typically SOAP extensions are used to handle data encryption or to compress data to provide better performance. SOAP extensions are often used in conjunction with a custom SOAP header for user authentication.
- You can use custom SOAP extensions to handle unhandled exceptions for Web Services.
- For this solution, code need to be added in AfterSerialize stage to check for unhanded SOAP exceptions.
- SOAP extension can be used to override the processing of the SOAP message on the Web server. On the Web server, there are four stages associated with these steps. Each of these stages is repeated twice.
1. BeforeSerialize
2. AfterSerialize
3. BeforeDeserialize
4. AfterDeserialize
Use OneWay Method

Mahesh ChandPosted Apr 15, 2013, 8:49 AM
Vipin, In Visual Studio, you can add a Web Reference by passing the WSDL URL of a Web service. Visual Studio creates stub classes for you and then you use them like any other class. Cheers!
Vipin JanardananPosted Dec 15, 2008, 4:56 AM
I want to knw hw is webservice applied in windows applications