MINI SUPPORTERS:

 

 

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

In the previous page, you finished creating your web service. In this page, I will provide a quick recap of why what you did earlier works, and I will conclude with an explanation of what the code does.

Taking a Look at the Web Service
Now that you have your web service created, let's take a look at what happens when you load your web service in the browser. This is the URL of my web service, so feel free to click on it if you don't feel like using the web service you created: http://www.kirupafx.com/WebService/TopMovies.asmx.

The page you see in your browser is the default page created for you automatically. It includes a lot of valuable information on how to use your web service, and you even get code snippets on how to implement your web service using different protocols.

We created two methods for our web service - GetTop10 and GetMovieAtNumber. The web service information page loaded in your browser, lists those two methods as operations your web service provides. Clicking on either the GetTop10 or GetMovieAtNumber operation provides you with the SOAP 1.1 and SOAP 1.2 implementations.

To dig deeper what causes your web service page to display this information? It is not simply because your code has it, it is because of the [WebMethod] tag directly above your public method:

[ the WebMethod attribute tags ensure that your methods are seen by the web service ]

The [WebMethod] tag makes sure that this particular method is exposed to the public via the web service interface. By omitting the [WebMethod] tag, you can ensure your method stays hidden from the public.

Code Explanation
Since you did copy and paste some code, before I conclude the tutorial, I want to make sure you know what each line of code does:

private string[] movieList = { "The Godfather (1972)",
"The Shawshank Redemption (1994)",
"The Godfather: Part II (1974)",
"The Lord of the Rings: The Return of the King (2003)",
"Casablanca", "Schindler's List",
"Shichinin no samurai (1954)",
"Buono, il brutto, il cattivo, Il (1966)",
"Pulp Fiction (1994)",
"Star Wars: Episode V - The Empire Strikes Back (1980)"};

In the above statement, I declare an array of strings[] called movieList. In my declaration, I go ahead and populate the array with the top ten movies listed on the IMDb web site.


[WebMethod]
public string[] GetTop10()
{
return movieList;
}

The GetTop10 method does nothing but return our earlier movieList array. Notice that the return type of this method is string[] - which is of the same type as the value you are returning.


[WebMethod]
public string GetMovieAtNumber(int input)
{
return movieList[input];
}

The GetMovieAtNumber returns a value of type string, but notice that it also takes an integer input. Your integer input acts as an index value, and that can be seen by looking at our return line:

return movieList[input];

You access specific values in your array by placing the index number next to the brackets such as what you see above. Array index numbering starts at 0, so be sure to take that into account when referring to specific values.

Because our movieList array contains objects of type string, the return value is also string. That works, for our method's return type is string also.


Need Help?

If you have questions, need some assistance on this topic, or just want to chat - please drop by our friendly forums and post your question. There are a lot of knowledgeable and witty people who would be happy to help you out. Plus, we have a large collection of smileys you can use

Share

Did you enjoy reading this and found it useful? If so, please share it with your friends:

If you didn't like it, I always like to hear how I can do better next time. Please feel free to contact me directly at kirupa[at]kirupa.com.

Cheers!

Kirupa Chinnathambi
about | facebook | twitter

 

1 | 2 | 3 | 4 | 5

SUPPORTERS:

cloud storage
cloud storage
kirupa.com's fast and reliable hosting provided by Media Temple. Creative web apps. Make your own free flash banners and photo slideshows.
HTML5 CSS3 Mobile Gallery for iPhone, iPad Flash effects. Art without coding.
Flipping Book - page flip flash component. Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery
X-Platform Application Development for Flash Free Flash Components Download - XML Templates, Players and Galleries.

two computer monitors

US Direct

Learn how to advertise on kirupa.com  
 
SHARE:



MINI SUPPORTERS: