Creating a Web Service

There are two broad aspects to web service development: creating the web service and consuming the web service. You'll start by creating a simple web service that provides a simulated stock information service. Your web service will expose two methods:

    Function GetName(stockSymbol As String) as String
    Function GetPrice (stockSymbol As String) as Float

Tip

If this web service were an actual production program, the data returned would be fetched from a live database. In order not to confuse web service issues with data access issues, the data in this chapter will be stored in a two-dimensional array of strings.

Begin by creating a new web site named StockPriceWebService. Be sure to click on ASP.NET Web Service in the templates window, as shown in Figure 14-1.

Visual Studio 2005 does a lot of the work of setting up your web service, including adding the necessary <WebService> attributes to your class, and creating a template method (HelloWorld) complete with <WebMethod> attributes. For more on attributes, see the note on attributes in Chapter 12.

Creating a web service

Figure 14-1. Creating a web service

You'll add a two dimensional array of stock symbols with their names and fictional prices, as shown in Example 14-1.

Example 14-1. Two-dimensional array of stock symbols and prices

Dim stocks As String(,) = _ { _ {"MSFT", "Microsoft", "25.22"}, _ {"DELL", "Dell Computers", "42.12"}, _ {"INTC", ...

Get Programming Visual Basic 2005 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.