Now that you have been introduced to Web services, let's dive in and actually create one. I find that most technical explanations of Web services are pointless until someone actually creates a Web service. So, to start with, open Visual Studio and select File New Project. From the Visual Basic Projects node, click the ASP.NET Web Service template, as shown in Figure 11-1. Click OK to create the Web service application with the default name of WebService1.
Figure 11-1: The New Project dialog box with an ASP.NET template selected
For your purposes, you want the Web service to be in the same virtual directory as your NorthwindTraders application.
Note | This is by no means a necessity. You could make the call to your objects from another Internet Information Server (IIS) virtual directory, but this approach simplifies things a great deal. Although Web services are quite simple to implement, there are many choices to make while securing and deploying the individual components. |
To move the location, close Visual Studio and navigate to the \wwwroot\webservice1 folder. Copy all of the files in the folder except the web.config file (because you do not want to overwrite your web.config file) and the bin folder and then paste these files into the \wwwroot\northwind folder. Finally, in the northwind folder, edit the webservice1.vbproj.webinfo file with Notepad. Listing 11-3 shows the original file.
Listing 11-3: The Webservice1.vbproj.webinfo File
<VisualStudioUNCWeb> <Web URLPath = "http://localhost/webservice1/WebService1.vbproj" /> </VisualStudioUNCWeb>
Change the URLPath so that it reads as follows:
<Web URLPath = "http://localhost/northwind/WebService1.vbproj" />
Now you can close and save the file. Finally, navigate to the project folder (this is usually located in \My Documents\Visual Studio Projects\Webservice1) and edit the webservice1.sln file with Notepad (see Listing 11-4). Change the location from http://localhost/Webservice1/WebService1.vbproj to http://localhost/northwind/WebService1.vbproj.
Listing 11-4: The webservice1.sln File
Microsoft Visual Studio Solution File, Format Version 8.00 Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "WebService1", "http://localhost/Webservice1/WebService1.vbproj", "{E05A1271-91EB-4A84-8F7F- 000A1065D7DE}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug Release = Release EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {E05A1271-91EB-4A84-8F7F-000A1065D7DE}.Debug.ActiveCfg = Debug|.NET {E05A1271-91EB-4A84-8F7F-000A1065D7DE}.Debug.Build.0 = Debug|.NET {E05A1271-91EB-4A84-8F7F-000A1065D7DE}.Release.ActiveCfg = Release|.NET {E05A1271-91EB-4A84-8F7F-000A1065D7DE}.Release.Build.0 = Release|.NET EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection GlobalSection(ExtensibilityAddIns) = postSolution EndGlobalSection EndGlobal
Next, double-click the webservice1.sln file to bring Visual Studio back up.