Creating a Web Service - Page 3
       by kirupa  |  11 August 2006

In the previous page, we slowly started setting up our project to host the web service. In this page, you will actually add the web service to your site.

  1. In your Solution Explorer, right click on an empty area and select the menu-item for New Folder. create a new folder called WebService.

[ create a new folder called WebService ]

  1. Once your WebService folder has been created, right click on it and select Add New Item. The Add New Item window will appear, and from this window, click on the Web Service icon:

[ select Web Service from the Add New Item window ]

  1. From the same Add New Item window, in the Name text field, enter TopMovies.asmx, ensure that the language is set to Visual C#, and check the box next to Place code in separate file as shown in the following image:

[ name your item TopMovies.asmx and ensure Visual C# is selected for language ]

  1. Once you have made the necessary changes to your Add New Item window, press the Add button. After a few moments, you will find that two files are created for you - TopMovies.asmx and TopMovies.cs:

[ the two locations your new web service creates its files ]

  1. We will mainly be working with the TopMovies.cs file. If you open your TopMovies.asmx file, you will find that it doesn't contain anything more than a reference to your TopMovies.cs file. With that said, double click on TopMovies.cs to display its code in your main window.
  2. When you open TopMovies.cs, you will find that some code has already been provided for you. Let's do some basic bookkeeping! Replace the text "Summary description for TopMovies" with "Provides a list of the Top 10 Movies as voted on by IMDb users."

    Next, in the Namespace = "...." area, replace the URL/path with the URL/path of your main Web site. I will explain later what that does. The changed lines of your code should look similar to the following:

[ the tags that define your web service ]

Right now, we created the web service and are in the process of modifying it. On the next page, we will go a step further and add some code to make our TopMovies web service do something useful.

Onwards to the next page.

1 | 2 | 3 | 4 | 5




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.