9.6. Adding a Web Reference to a Project

You can connect to the preceding Web service by creating a Web reference. You then consume the service in an ASP.NET Web page.

Before a page can use functions on another server, it needs to know where to find the service and how to invoke the functions. Visual Web Developer includes graphical tools for discovering a Web service and creating the connection. Follow these steps to add a Web reference:

  1. In Solution Explorer, right-click the project name and choose Add Web Reference from the context menu.

  2. In the URL box, enter the Internet address of the Web service — for example, http://www.kjopc.com/rgbservice.asmx — and then click Go.

    If your Web service is in the same project, click the Web Services In This Solution link (in the lower pane) to find it.

    As shown in Figure 9-4, the dialog box connects to the URL and reports on the Web services that it finds.

    Figure 9-4. Adding a Web reference.
  3. In the Web Reference Name box, type the name of this reference (for example, getrgbservice) and then click Add Reference.

The IDE puts the Web reference into a new folder called App_WebReferences in Solution Explorer. It also adds an entry to the web.config file that includes the URL and name of the Web service. On my system, it looks like the following:

<appSettings> <add key="getrgbservice.rgbservice" value="http://www.kjopc.com/rgbservice.asmx"/> </appSettings> ...

Get ASP.NET 3.5 For Dummies® 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.