Link for code samples used in the demo
Link for all dot net and sql server video tutorial playlists
Here are the steps to consume the web service that we have created in Part 1.
Step 1: Right click on WebServicesDemo solution in solution explorer and add new asp.net
web application project and name it CalculatorWebApplication.
Step 2: Now we need to add a reference to web service. To achieve this
a) Right click on References folder in the CalculatorWebApplication project and select Add Service Reference option
b) In the Address textbox of the Add Service Reference window, type the web service address and click GO button. In the namespace textbox type CalculatorService and click OK.
Step 3: Right click on CalculatorWebApplication project in solution explorer and add new webform.
Step 3: Copy and paste the following HTML
Get the HTML for the page from my blog as youtube doesn't allows HTML in the description of the video.
Step 4: Copy and paste the following code in the code-behind file
protected void btnAdd_Click(object sender, EventArgs e)
CalculatorService.CalculatorWebServicesSoapClient client =
int result = client.Add(Convert.ToInt32(txtFirstNumber.Text),
lblResult.Text = result.ToString();
In an interview the interviewer may ask you the following questions related to consuming a web service.
1. What is WSDL and what is it's purpose
2. How is a proxy class generated
3. What is the use of a proxy class
4. What actually happens when a web service reference is added
The following 2 paragraphs should provide the answers for the above questions
Visual studio generates a proxy class using the WSDL (Web Service Description Language) document of the web service. The WSDL document formally defines a web service. It contains
1. All the methods that are exposed by the web service
2. The parameters and their types
3. The return types of the methods
This information is then used by visual studio to create the proxy class. The client application calls the proxy class method. The proxy class will then serialize the parameters, prepares a SOAP request message and sends it to the web service. The web service executes the method and returns a SOAP response message to the proxy. The proxy class will then deserialize the SOAP response message and hands it the client application. We don't have to serialize or deserialize dot net CLR objects to and from SOAP format. The proxy class takes care of serialization and deserialization and makes the life of a developer much easier.