Sitefinity CMS

Web Services Send comments on this topic.
See Also
Developing with Sitefinity > Data Access > Non-provider Data Access > Web Services

Glossary Item Box

Web services allow objects from two different computers to interact with each other. By connecting to a Web Service, applications can connect to a business logic layer outside of its physical location. Visual Studio makes a copy of the web services project and encapsulates it in a Web Services Description Language (WSDL) file, so your application can use it like an assembly. You can connect to a Web Service in Sitefinity like you would in a normal .NET application by creating a user control, binding to the Web Service and adding a reference to it:

Adding a Web Reference

  1. Open your Sitefinity project in Visual Studio
  2. Right click on the solution and click on Add a Web Reference
  3. In the UDDI dialog box that appears, type in the location of the web service

Creating the User Control

  1. Create a folder called Files in the root directory, if the folder name does not already exist
  2. Create a new user control
  3. Place a data-bound tool on the page, such as a RadGrid, to view the data
  4. You can optionally include other controls, such as ones to enable AJAX or to filter data, as shown in the code sample and screen shot below this sentence:

 

BankRateUserControl.ascx Copy Code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="BankRateUserControl.ascx.cs" Inherits="Files_BankRateUserControl" %>
<
telerik:RadDatePicker runat="server" ID="RadDatePicker1">
</
telerik:RadDatePicker>
<
asp:Button runat="server" ID="btnCheck" Text="Refresh" OnClick="btnCheck_Click" />
<
telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid_NeedDataSource"
AutoGenerateColumns="false">
<
MasterTableView>
<
Columns>
<
telerik:GridBoundColumn DataField="date" HeaderText="date">
</
telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="rateType" HeaderText="rateType">
</
telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="rate" HeaderText="rate">
</
telerik:GridBoundColumn>
<
telerik:GridBoundColumn DataField="unit" HeaderText="unit">
</
telerik:GridBoundColumn>
</
Columns>
</
MasterTableView>
</
telerik:RadGrid>
<
telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<
AjaxSettings>
<
telerik:AjaxSetting AjaxControlID="btnCheck">
<
UpdatedControls>
<
telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</
UpdatedControls>
</
telerik:AjaxSetting>
</
AjaxSettings>

</
telerik:RadAjaxManager>

Web Service

Bind the data

  1. In the business logic layer, add a using (Imports for VB.NET) statement and add references to the WSDL’s name (which in this case is lt.lb.webservices) and the System.Xml namespace.
  2. Bind your data-bound control in the business logic layer as shown in the following code sample:

 

BankRateUserControl.ascx.cs Copy Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Telerik.Web.UI;
using lt.lb.webservices;
using System.Xml;
public partial class Files_BankRateUserControl : System.Web.UI.UserControl
{
   
protected void Page_Load(object sender, EventArgs e)
   {
   }
   
protected void RadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
   {
       LBInterestRates lbInterestRates =
new LBInterestRates();
       XmlNode interestRatesByDate = lbInterestRates.getLBInterestRatesByDate
       (RadDatePicker1.SelectedDate.HasValue?
       RadDatePicker1.SelectedDate.Value.ToString(
"yyyy.MM.dd")
       : DateTime.Now.ToString(
"yyyy.MM.dd"));
       DataSet ds =
new DataSet();
       XmlNodeReader reader =
new XmlNodeReader(interestRatesByDate);
       ds.ReadXml(reader);
       ((RadGrid)source).DataSource = ds;
   }
   
protected void btnCheck_Click(object sender, EventArgs e)
   {
       RadGrid1.Rebind();
   }
}

 

Once these steps are complete, you must upload the User Control to Sitefinity.  

See Also