Thursday, November 12, 2009

Partial Class

Partial class are new feature in 2.0 Framework where single class is split among N-number of files,this is usefull when more than one developer wants to work on a same class,through class is split into N-number of files only one constructor will exist among all class files.When CLR complies the partial class after seeing Partial keyword CLR checks for class with same name and combines all partial class and compile it.
Example for partial class are all ASPX pages

Wednesday, November 11, 2009

Web Service

Web services which promote software reusability in distributed systems where applications execute across multiple computers on a network. A Web service is a class that allows its methods to be called by methods on other machines via common data formats and protocols, such as XML and HTTP. In .NET, the over-the-network method calls are commonly implemented through the Simple Object Access Protocol (SOAP), an XML-based protocol describing how to mark up requests and responses so that they can be transferred via protocols such as HTTP. Using SOAP, applications represent and transmit data in a standardized XML-based format.

Note1: Microsoft is encouraging software vendors and e-businesses to deploy Web services. As increasing numbers of organizations worldwide have connected to the Internet, the concept of applications that call methods across a network has become more practical.

Note2: Web services are not the best solution for certain performance-intensive applications, because applications that invoke Web services experience network delays. Also, data transfers are typically larger because data is transmitted in text-based XML formats.

Uses: Web services facilitate collaboration and allow businesses to grow. By purchasing Web services and using extensive free Web services that are relevant to their businesses, companies can spend less time developing new applications. E-businesses can use Web services to provide their customers with enhanced shopping experiences. Consider an online music store. The store's Web site provides links to information about various CDs, enabling users to purchase the CDs or to learn about the artists

.NET Web Services Basics
A Web service is a software component stored on one machine that can be accessed by an application (or other software component) on another machine over a network. The machine on which the Web service resides is referred to as a remote machine. The application (i.e., the client) that accesses the Web service sends a method call over a network to the remote machine, which processes the call and returns a response over the network to the application. This kind of distributed computing benefits various systems. For example, an application without direct access to certain data on another system might be able to retrieve this data via a Web service. Similarly, an application lacking the processing power necessary to perform specific computations could use a Web service to take advantage of another system's superior resources.
Requests to and responses from Web services created with Visual Web Developer are typically transmitted via SOAP. So any client capable of generating and processing SOAP messages can interact with a Web service, regardless of the language in which the Web service is written.
Web services have important implications for business-to-business (B2B) transactions. They enable businesses to conduct transactions via standardized, widely available Web services rather than relying on proprietary applications. Web services and SOAP are platform and language independent, so companies can collaborate via Web services without worrying about the compatibility of their hardware, software and communications technologies. Companies such as Amazon, Google, eBay and many others are using Web services to their advantage.

Methods in a Web service are invoked through a Remote Procedure Call (RPC). These methods, which are marked with the WebMethod attribute, are often referred to as Web service methods or simply Web methods-we refer to them as Web methods from this point forward. Declaring a method with attribute WebMethod makes the method accessible to other classes through RPCs and is known as exposing a Web method.

Discovering Web Services
Once you implement a Web service, compile it and deploy it on a Web server a client application can consume (i.e., use) the Web service. However, clients must be able to find the Web service and learn about its capabilities. Discovery of Web services (DISCO) is a Microsoft-specific technology used to locate Web services on a server. Four types of DISCO files facilitate the discovery process: .disco files, .vsdisco files, .discomap files and .map files.
DISCO files consist of XML markup that describes for clients the location of Web services. A .disco file is accessed via a Web service's ASMX page and contains markup specifying references to the documents that define various Web services. The resulting data that is returned from accessing a .disco file is placed in the .discomap file.
A .vsdisco file is placed in a Web service's application directory and behaves in a slightly different manner. When a potential client requests a .vsdisco file, XML markup describing the locations of Web services is generated dynamically, then returned to the client. First, the .NET Framework searches for Web services in the directory in which the .vsdisco file is located, as well as that directory's subdirectories. The .NET Framework then generates XML that contains references to all the Web services found in this search.
Note that a .vsdisco file does not store the markup generated in response to a request. Instead, the .vsdisco file on disk contains configuration settings that specify the .vsdisco file's behavior. For example, developers can specify in the .vsdisco file certain directories that should not be searched when a client requests a .vsdisco file. Although a developer can open a .vsdisco file in a text editor and examine its contents, this is rarely necessary-a .vsdisco file is intended to be requested (i.e., viewed in a browser) by clients over the Web. Every time this occurs, new markup is generated and displayed.
Using .vsdisco files benefits developers in several ways. These files contain only a small amount of data and provide up-to-date information about a server's available Web services. However, .vsdisco files generate more overhead (i.e., require more processing) than .disco files do, because a search must be performed every time a .vsdisco file is accessed. Thus, some developers find it more beneficial to update .disco files manually. Many systems use both types of files. As we discuss shortly, Web services created using ASP.NET contain the functionality to generate a .disco file when it is requested. This .disco file contains references only to files in the current Web service. Thus, a developer typically places a .vsdisco file at the root of a server; when accessed, this file locates the .disco files for Web services anywhere on the system and uses the markup found in these .disco files to return information about the entire system.

Determining a Web Service's Functionality
After locating a Web service, the client must determine the Web service's functionality and how to use it. For this purpose, Web services normally contain a service description. This is an XML document that conforms to the Web Service Description Language (WSDL)-an XML vocabulary that defines the methods a Web service makes available and how clients interact with them. The WSDL document also specifies lower-level information that clients might need, such as the required formats for requests and responses.
WSDL documents are not meant to be read by developers; rather, WSDL documents are meant to be read by applications, so they know how to interact with the Web services described in the documents. Visual Web Developer generates an ASMX file when a Web service is constructed. Files with the .asmx filename extension are ASP.NET Web service files and are executed by ASP.NET on a Web server (e.g., IIS). When viewed in a Web browser, an ASMX file presents Web method descriptions and links to test pages that allow users to execute sample calls to these methods. The ASMX file also specifies the Web service's implementation class, and optionally the code-behind file in which the Web service is defined and the assemlies referenced by the Web service. When the Web server receives a request for the Web service, it accesses the ASMX file, which, in turn, invokes the Web service implementation. To view more technical information about the Web service, developers can access the WSDL file (which is generated by ASP.NET).

ASP.NET generates WSDL information dynamically rather than creating an actual WSDL file. If a client requests the Web service's WSDL description (either by appending ?WSDL to the ASMX file's URL or by clicking the Service Description link), ASP.NET generates the WSDL description, then returns it to the client for display in the Web browser.
Generating the WSDL description dynamically ensures that clients receive the most current information about the Web service. It is common for an XML document (such as a WSDL description) to be created dynamically and not saved to disk.
When a user clicks the Service Description link at the top of the ASMX page the browser displays the generated WSDL document containing the service description for our Web service
Testing a Web Service's Methods
Below the Service Description link, the ASMX page lists the methods that the Web service offers. Clicking any method name requests a test page that describes the method .The test page allows users to test the method by entering parameter values and clicking the Invoke button. Below the Invoke button, the page displays sample request-and-response messages using SOAP and HTTP POST. These protocols are two options for sending and receiving messages in Web services. The protocol that transmits request-and-response messages is also known as the Web service's wire format or wire protocol, because it defines how information is sent "along the wire." SOAP is the more commonly used wire format, because SOAP messages can be sent using several transport protocols, whereas HTTP POST must use HTTP. When you test a Web service via an ASMX page, the ASMX page uses HTTP POST to test the Web service methods. when we use Web services in our C# programs, we employ SOAP-the default protocol for .NET Web services.
Building a Client to Use a Web Service
let's examine the parts of a .NET Web service client. A .NET client can be any type of .NET application, such as a Windows application, a console application or a Web application. You can enable a client application to consume a Web service by adding a Web reference to the client. This process adds files to the client application that allow the client to access the Web service.
To add a Web reference in Visual C# 2005, right click the project name in the Solution Explorer and select Add Web Reference.... In the resulting dialog, specify the Web service to consume. Visual C# 2005 then adds an appropriate Web reference to the client application.
NET Web service client after a Web reference has been added.

When you specify the Web service you want to consume, Visual C# 2005 accesses the Web service's WSDL information and copies it into a WSDL file that is stored in the client project's Web References folder. This file is visible when you instruct Visual C# 2005 to Show All Files.

NOTE: A copy of the WSDL file provides the client application with local access to the Web service's description. To ensure that the WSDL file is up-to-date, Visual C# 2005 provides an Update Web Reference option (available by right clicking the Web reference in the Solution Explorer), which updates the files in the Web References folder.] The WSDL information is used to create a proxy class, which handles all the "plumbing" required for Web method calls (i.e., the networking details and the formation of SOAP messages). Whenever the client application calls a Web method, the application actually calls a corresponding method in the proxy class. This method has the same name and parameters as the Web method that is being called, but formats the call to be sent as a request in a SOAP message. The Web service receives this request as a SOAP message, executes the method call and sends back the result as another SOAP message. When the client application receives the SOAP message containing the response, the proxy class deserializes it and returns the results as the return value of the Web method that was called. The Below figure depicts the interactions among the client code, proxy class and Web service.



Interaction between a Web service client and a Web service


The .NET environment hides most of these details from you. Many aspects of Web service creation and consumption-such as generating WSDL files, proxy classes and DISCO files-are handled by Visual Web Developer, Visual C# 2005 and ASP.NET. Although developers are relieved of the tedious process of creating these files, they can still modify the files if necessary. This is required only when developing advanced Web services-none of our examples require modifications to these files.


Simple Object Access Protocol (SOAP)
The Simple Object Access Protocol (SOAP) is a platform-independent protocol that uses XML to make remote procedure calls, typically over HTTP. Each request and response is packaged in a SOAP message-an XML message containing the information that a Web service requires to process the message. SOAP messages are written in XML so that they are human readable and platform independent. Most firewalls-security barriers that restrict communication among networks-do not restrict HTTP traffic. Thus, XML and HTTP enable computers on different platforms to send and receive SOAP messages with few limitations.
When a program invokes a Web method, the request and all relevant information are packaged in a SOAP message and sent to the server on which the Web service resides. When the Web service receives this SOAP message, it begins to process the contents (contained in a SOAP envelope), which specify the method that the client wishes to execute and any arguments the client is passing to that method. This process of interpreting a SOAP message's contents is known as parsing a SOAP message. After the Web service receives and parses a request, the proper method is called with the specified arguments (if there are any), and the response is sent back to the client in another SOAP message. The client parses the response to retrieve the result of the method call.

Publishing and Consuming Web Services
This section presents several examples of creating (also known as publishing) and using (also known as consuming) Web services. Recall that an application that consumes a Web service actually consists of two parts-a proxy class representing the Web service and a client application that accesses the Web service via an instance of the proxy class. The instance of the proxy class passes a Web method's arguments from the client application to the Web service. When the Web method completes its task, the instance of the proxy class receives the result and parses it for the client application. Visual C# 2005 and Visual Web Developer create these proxy classes for you. We demonstrate this momentarily.