Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The web service web part enables you to connect to web service end points. This web part requires that you specify a web service URL and it implements a GetDataSet() method. The Kentico WebProject contains an example that can be customized. Let's create an example of a web service that allows you retrieve a lunch list using a GetDataSet() method and the following steps.
In the Kentico CMS WebProject, double-click the \App_Code\CMSPages\WebService.cs file, as shown in the following screenshot:
In the WebService.cs GetDataSet() method, replace the existing code with the following:
/// <summary>
/// Returns the data from DB
/// </summary>
/// <param name="parameter">String parameter for sql command</param>
[WebMethod]
public DataSet GetDataSet(string parameter)
{
// INSERT YOUR WEB SERVICE CODE AND RETURN THE RESULTING DATASET
//-- Instantiate the data set and table
DataSet lunchDS = new DataSet();
DataTable lunchTable = lunchDS.Tables.Add();
//-- Add columns to the data table
lunchTable.Columns.Add("ID", typeof(int));
lunchTable.Columns.Add("weekDay", typeof(string));
lunchTable.Columns.Add("Lunch", typeof(string));
//-- Add rows to the data table
lunchTable.Rows.Add(1, "Monday", "Kobe River Snake Farm Specialty Hamburgers");
lunchTable.Rows.Add(2, "Tuesday", "Canyon River Beef Stew");
lunchTable.Rows.Add(3, "Wednesday", "Smoke Halibut");
lunchTable.Rows.Add(4, "Thursday", "Specialty Ham Sandwich");
lunchTable.Rows.Add(5, "Friday", "Trout Almondine");
return lunchDS;&;
}
In the Visual Studio Solution Explorer, select the WebService.cs file and run the Kentico CMS project. In the WebService page, click the GetDataSet method, as shown in the following screenshot:
Remember the URL
Make sure to write down the page URL for the .asmx page that you see in the previous screenshot. We will use this shortly when we implement the web services web part.&;
Log in to CMS Desk, select the Content tab, Home page, Design tab, and in zoneCenter, select the add web part icon.
In the Select web part screen, select the Web services folder, Grid for web service web part, and then select OK, as shown in the following screenshot:
In the Web part properties (Grid for web service), enter the following values and then select OK.&;
| Tab | Property | Value |
|---|---|---|
| Default | Web part title | Weekly Lunch menu |
| No data behavior | Hide if no record found | Checked |
| Web service settings | Web service URL (.asmx file) | The .asmx page URL |
| HTML Envelope | Web part container | Orange box |
Select live site to view the web part, as shown in the following screenshot: