With ASP.NET, it is easy to set up a Web Service that returns a dataset which you can use as a data source for an ActiveReport.
This walkthrough illustrates how to create a simple Web Service that returns a dataset.
This walkthrough is split up into the following activities:
- Creating an ASP.NET Web Service project
- Adding code to create the Web Method
- Testing the Web Service
- Publishing the Web Service
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.
When you have completed this walkthrough, you will have created a Web Service that returns a dataset which can be used as a data source for an ActiveReport.
Creating an ASP.NET Web Service project
To create an ASP.NET Web Service project in Visual Studio 2003
- From the File menu, select New > Project.
- In the Templates window of the New Project dialog, select ASP.NET Web Service.
- Change the name of the project from WebService1 to DataSetWS.
- Click OK to open the new project in Visual Studio.
To create an ASP.NET Web Service project in Visual Studio 2005
- From the File menu, select New > Web Site.
- In the Templates window of the New Web Site dialog, select ASP.NET Web Service.
- Change the name of the project from WebService1 to DataSetWS.
- Click OK to open the new project in Visual Studio.
Adding code to create the Web Method
To write the code to create the Web Method
- Right-click on the Service1.asmx page and select View Code to display the code view for the page. (In Visual Studio 2005, the code view displays by default.)
- Add the following code under the Web Services Designer Generated Code section to create the Web Service. (In Visual Studio 2005, just replace the existing WebMethod and function with this code.)
'Visual Basic Private connString As String 'Change your data source path as needed <WebMethod(Description:="Returns a DataSet containing all Products")> _ Public Function GetProduct() As Data.DataSet connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data" Dim adapter As New Data.OleDb.OleDbDataAdapter("select * from products", connString) Dim ds As New Data.DataSet() adapter.Fill(ds, "Products") Return ds End Function //C# //Change your data source path as needed private static string connString = "Provider=Microsoft.Jet.OLEDB.4.0;C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data"; [WebMethod(Description="Returns a DataSet containing all Products")] public Data.DataSet GetProduct() { Data.OleDb.OleDbDataAdapter adapter; Data.DataSet ds; adapter = new Data.OleDb.OleDbDataAdapter("select * from products", connString); ds = new Data.DataSet(); adapter.Fill(ds, "Products"); return ds; }
Testing the Web Service
To test the Web Service
- Press F5 to run the project.
- Click "GetProduct" in the list of supported operations.
- Click the Invoke button to test the Web Service operation.
- If the test is successful, you will see a valid XML schema of the Northwind products table.
Publishing the Web Service
To publish the Web Service
- In the Solution Explorer, right-click the project name and select Publish Web Site.
- Click the OK button.
- This makes the Web Service available for consumption by other projects.