Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 6. System Integration > Time for action — building a web service

Time for action — building a web service

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.

  1. In the Kentico CMS WebProject, double-click the \App_Code\CMSPages\WebService.cs file, as shown in the following screenshot:

  2. 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;&;
    }
    
    
    					  
  3. 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.&;


  4. From the WebService page, select the Invoke button, as shown in the following screenshot:&;

  5. View the web service return values, as shown in the following screenshot:

    Now that we have completed the web service and implemented the GetDataSet method, let's go ahead and display the weekly lunch menu web service using the web service web part by carrying out the following steps:&;

  6. Log in to CMS Desk, select the Content tab, Home page, Design tab, and in zoneCenter, select the add web part icon.

  7. 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:

  8. 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


  9. Select live site to view the web part, as shown in the following screenshot:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial