And remember, I have written this article only focusing on beginners. So let us start step-by-step so beginners can understand it very easily.
You need to keep a Web Service application in running mode so it can be accessible for use, so go to my article Introduction to Web Services and create a Web Service and keep it in running mode I hope you have done that.
What does consuming mean?
Many beginners are confused about what means consuming means, but its very simple, it means to use the Web Services in an application.
I have created Web Services and now I want to use it in a real requirement so I used it in an ASP.Net Web Application. In other words, I am consuming the Web Service in an ASP.Net web application. Similarly you can use the same Web Service in Windows, console application, Java and other applications.
I hope you understand the word "consuming".
So let us create the simple ASP.Net Web Application as:
- "Start" - "All Programs" - "Microsoft Visual Studio 2010".
- "File" - "New" - "Project..." then in the New Project window "C#" - "Empty Project" (to avoid adding a master page).
- Give the project a name, such as "Consumingwebservice" or another as you wish and specify the location.
- Then right-click on Solution Explorer and select "Add New Item" - "Default.aspx" page.
- Then drag three Text Boxes, one Button, and one Label onto the "Default.aspx" page.
I hope you understand it.
Now your Solution Explorer of ASP.Net Web Application will be as in the following:
Adding a Web Service Reference in the ASP.Net Web Application
The most important task whem consuming a Web Service in an ASP.Net Web Application is adding the Web Service reference into the ASP.Net web application. So how to add it? Let us see the procedure.
1. Right-click on the ASP.Net Web Application and click on "Add Service Reference" as in the following:
2. Then after clicking on the above option, the following window will appear, then click on the "Advanced" tab.
3. Now after clicking on the Advanced tab, it will show the following window then click on the "Add Web Reference" option as in the following in a circle:
4. After clicking on the Add Web Reference tab, it will show the following window. Now this is a very important step, when adding the web reference to the ASP.Net web Application. Since you see "URL" option in the following window, on that window we need to paste or type the Web Service URL address.
So how to add the URL Reference in the preceding URL box, let us see the procedure again.
- Run the Web Service we created in my article Introduction toWeb Service with Example in ASP.Net by clicking on F5 or whatever other option you are familiar with, it will then show the following web page.
As you clearly see there, in the preceding window, it displays the method named "converttodaysweb" as we created in our Web Service, now just you need to copy the preceding URL that I have circled in red and paste it into the Step 4 window URL option, then the Step 4 window will look as in the following:
-----What After Pasting the URL in the preceding URL box
- Web Reference Name
- Also refer to my previous article about creating a Web Service.
I hope that beginners as well as students understand the creation and consumption of Web Services in ASP.Net web applications using my two articles. If you have any suggestion regarding this articles then please contact me. Student suggestions are also welcomed.