Using a web service within a .NET program is a straightforward process. To begin, you must add to the program a Web Reference that corresponds to the web service. To do so, you must know the location of the WSDL file that describes the web service.
If you examine websites that make web services available to programmers, you will find that the sites always contain a link to the web service’s WSDL file. If you click the link, your browser will display XML-based data that describe the service, similar to that shown in Figure 1.6. XML, as you know, is the Extensible Markup Language that developers use to describe data. Throughout this book, you will make extensive use of WSDL, the web service definition language. For now, think of WSDL as providing a description of the methods (functions) a web service provides, as well as a description of the parameters each method requires.
For now, you can ignore the XML statements that describe the service. Instead, note the Web address that appears within the browser’s address field. You can either write down the address or cut and paste the address into the Visual Studio .NET Add Web Reference dialog box.
Figure 1.6: Viewing a web service’s WSDL file
After you add a Web Reference to your program code for the web service, you must then create a corresponding object within your source code. The following statement creates an object that a Visual Basic .NET program can use to interact with the FastWeather web service:
Dim WeatherRequest As New net.serviceobjects.ws.FastWeather()
After you add a service’s Web Reference to your program, Visual Studio .NET will display the reference within the Class View window. As you view the web services within the Class View window, you will find that most web service object names will begin with letter combinations such as net. If you simply type the first two letters of the name, Visual Studio .NET usually will display the service’s remaining characters, making it very easy for you to enter the correct object names.
Regardless of the web service you want to use from within a .NET program and regardless of whether you are writing the program using Visual Basic .NET and C# or if you are creating an ASP.NET page, the steps you will perform are the same. If your code requires multiple web services, you must perform these steps for each object.