Consuming a hosted Web Service using Visual Studio, specifically VWD 2010

In this blog we will examine the process to “Consume” a web service located on the web.

Starting the Web Site construction

To begin, create the default web site in Visual Web Developer Express 2010, the process is basically the same as with any of the Visual Studio web tools. The installation is faster, about 10 minutes from start of download to completion. To get started select the ASP.NET Web Site, and I will be using the Visual C# language, mainly because of its built in support of refactoring. For the next few figures, I will be comparing Visual Web Developer express 2010 (VWD 2010) to Visual Web Developer express 2008 (VWD 2008)

Figure 1: Visual Web Developer Express 2010 New Web Site Dialog Box


Figure 2: Visual Web Developer Express 2008 New Web Site Dialog Box


Figure 3: VWD 2010, Solution Explorer has more files in it then VWD 2008, many for security purposes


Figure 4: VWD 2008 doesn't have the security items or the site master


From now on in this blog entry I will be using VWD 2010 express and refer to it as VWD, you will be able to use VWD 2008 Express, the pictures will be slightly different.

Building your Web Service Consuming application

You will need to add a “Standard” button to the Default.aspx and a Label to use the following code, here is what the code will look like when you are done, but don’t enter the code yet:

protected void Button1_Click(object sender, EventArgs e)


us.z25.Service ws = new us.z25.Service();

Label1.Text = ws.HelloWorld();


Getting started with the User Interface or UI:

To create the Button1_Click event, that you see in the introduction to this section, you will need to:

· Add a button to Default.aspx and double click on it in the Visual Studio or Visual Web Dev form (the VSD 2008 Express default is different than the VSD 2010 default web page).

· Add a label, you can change the text, but that isn’t required.

· You DO NOT need to actually type in the code for the event, you will need to type a little code to consume the web service.

Figure 5: How your form might look in VWD 2010 Express


Add Web Reference

Figure 6: Right click the project at the top of the Solution Explorer and then select Add Web Reference


Here is the Add Web Reference dialog box, for the URL, make sure to use your own URL after 1/1/2010, you can check to see if I have anything at z25, you will need to navigate to the site to see what I have. If you get an error, it could mean that I have taken service.asmx off the site or moved it.

Make user to note the Web Reference name out of the textbox just above the Add Reference button.

Figure 7: Add Web Reference, type in the URL plus the service.asmx. Note that a change needs to be made to our hello world application



Writing the code to consume a web service

First off let’s talk about the properties of the button and label, for this example, don’t change any of the properties or IDs. Make sure that they look like the following:



This is fairly simple coding exercise. Double click the button on Default.aspx, then using the Web Reference name, in this case: us.z25.Service (because Service was the name of the Web Method in the Web service created by VWD by default)

Figure 8: When you double click the button you will see this screen, or a similar screen.


Figure 9: Now construct the Service Class exposed by the Web Service


Figure 10: Now add the Service class, do it on both sides



Figure 11: For reference purposes I have included the default web service from the previous blog entry here, note that there is a public class Service that exposes the method HelloWorld:

Run your application

Press the F5 key or ctrl+F5, after a few seconds you will see the following in VWD 2010


Click the button on your new webpage. After a few seconds the web service at will return the phrase: Hello World and look like the following:




Great work!  You have successfully consumed a simple web service!

Comments (8)

  1. Jeff Murri says:

    Great post. Thank you for this.

  2. Yury M says:

    Cool post. Thanks, very helpful 🙂

  3. RObert P says:

    What F***8 Cr**** images

  4. Surf4Fun says:

    RObert P, thanks for the feedback on those first three images, I will see if I can improve them.

    Awesome feedback, got my attention.  

    Now a little feedback for you: No need for the asterik cursing, personally I view all comments and take a look at what I think you are trying to say.  

    For many bloggers this type of language is ignored; makes the blogger upset; etc. In balance an equal number bloggers like any feedback.

    In the future, if you could focus your comments a little on the problem that would make the discourse on the web more polite in general.  

    However, feel free to post as you like here at devschool.  Communications is a part of learning.

    Instead of: "What F***8 Cr*** images"

    You might consider writing: "Images in this blog are blurred, it makes your blog look stupid."  

    See the latter makes your point, adds the important insult we all like to throw out (I have done my share) and allows me to quickly get to the point that you want to make.

    F***8 is short for one of the "seven" words and lends an unneccessary weight to the feedback.  For example you might want to save that for one of the various forums that are talk about the POS Ghostbusters 3 video game or the latest government/college/corporate screw-up.

    Cr*** images: Now this was appropriate weight, and I think you could use the full word without violating the "seven" word rule.

  5. Randy M says:

    Great stuff, thanks.  Would you be able to extend or convert this example, so that a batch job could use this code instead of invoking via ASP.NET?

  6. yadir says:

    lo que pasa es que tengo una aplicación en visual studio 2010 y la compilo desde visual y funciona bien (la aplicación es un servicio web), y apenas la publico el iis 8 (windows 8 ) el servicio no me deja entrar ala base de datos que esta creada en sqlserver 2008 r2, no se si es que local mente el iis tenga una configuración especifica sobre la entrada a consumir el servicio

  7. Surf4Fun says:

    Pido perdón, pero no tengo una respuesta para usted en esto. He cambiado de enfoque.

  8. Surf4Fun says:

    Pido perdón, pero no tengo una respuesta para usted en esto. He cambiado de enfoque.

Skip to main content