Web services are a very important new technology for exposing application logic to remote Web clients using HTTP and XML-based standards. For more information see http://msdn.microsoft.com/webservices.
This sample consists of a Web service and two client applications that consume the Web service. One client is a Web Form application, and the other is a Windows Forms application. The Web service exposes two Web methods that return data from the Northwind database. GetTenMostExpensiveProducts() is a simple Web method that returns a generic DataSet. It is consumed by the Web application. GetCustomerOrderHistory() demonstrates how to return a custom complex type--an instance of a class that has two public fields, one of which is a typed DataSet. This Web method is consumed by the Windows Forms application.
This application requires the release version of Visual Studio .NET Professional (or greater) and access to the Northwind database residing in SQL Server or the Microsoft Data Engine (MSDE). To install MSDE, do the following:
1. Open the Start menu, click Programs, click Microsoft .NET Framework SDK, and then click Samples and Quickstart Tutorials.
2. Click "Step 1: Install the .NET Framework Samples Database".
3. Open a command window, and CD to [FrameworkSDKInstallRoot]\Samples\Setup This is typically : C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Setup
4. Type: osql -E -S (local)\NetSDK -i InstNwnd.sql
To install the Web Service and Web Forms Client:
1. Double-click SetupWebs.vbs in the root folder. (Note: The Visual Studio .NET Solution file resides in the "How To" root folder, not at c:\inetpub\wwwroot\HowToBuildWebServices.)
To run the Web Forms client:
1. In the Solution Explorer,
right-click HowToWebServiceClient and then click Set as
StartUp Project.
2. Right-click Main.aspx and then click Set As Start Page.
3. Press F5 to build and run the sample.
If you get the following error the aspnet worker process is locking the Web-based DLLs. Take the corrective steps that follow.
Could not copy temporary files to the
output directory.
The file 'bin\HowToBuildWebServices.dll' cannot be copied to the run directory.
The process cannot access the file because it is being used by another process.
The file 'bin\HowToBuildWebServices.pdb' cannot be copied to the run directory.
The process cannot access the file because it is being used by another process.
1. Press CTRL + ALT + Delete
to open the Windows Task Manager.
2. Click the Processes tab.
3. Click the Image Name ListView header to sort aspnet_wp.exe
to the top.
4. Click aspnet_wp.exe and then click End Process.
5. Close Windows Task Manager.
To run the Windows Forms client:
1. In the Solution Explorer,
right-click VB.NET How-To Build Web Services (Client) and then
click Set as StartUp Project.
2. Press F5 to build and run the sample.
3. Sample Customer ID values are COMMI, GODOS, and ISLAT.
To run the Web Services directly, without the use of a client:
1. In the Solution Explorer,
right-click main.asmx and then click View in Browser.
2. Click the link for any of the Web methods to go to the test page. Sample
Customer ID values are COMMI, GODOS, and ISLAT.
To add a typed DataSet to the project for data from the Northwind database take the following steps:
1. In the Solution Explorer,
right-click the project, point to Add, and then click Add
New Item.
2. From Templates click DataSet. Give it a
name with a .xsd file extension and click Open. This will add
an XSD schema file to the project. From this file is generated
the typed DataSet class that derives from System.Data.DataSet.
3. Open the Server Explorer and expand the nodes under SQL Servers to find
the Northwind Stored Procedures.
4. Click and drag a stored procedure onto the design surface of the schema
file.
5. Right-click on the design surface and make sure Generate DataSet
is checked. If not, click it.
6. Press CTRL + S to save the schema, which generates the typed DataSet
class.
7. To view the typed DataSet class, in the Solution Explorer click the Show
All Files icon. Expand the .xsd node to see the .vb file of the
same name.
NOTE:
If you get an error when running the sample make sure that IIS has appropriate permissions to query tables in the local SQL Server. There are multiple ways to achieve this but the easiest way to do this for testing and running samples is to change the default <processModel> settings in machine.config. The steps to do this are as follows:
1. Navigate to
c:\[WINDOWSDIR]\Microsoft.NET\Framework\[FrameworkVersion]\Config
2. Open the Machine.Config file found there and change the
userName attribute so that it's value is SYSTEM (i.e.
userName="SYSTEM")
3. Save the File.
4. Open up a command prompt and type IISReset to restart IIS.
Another options to use that is more applicable for a production environment is
to give appropriate permissions to the ASPNET account in the appropriate
database.