This topic discusses the concepts of client data service, the type of service it supports, and provides information on the best practices and key scenarios to develop service-based applications using WebCombo.
This topic contains the following sections:
- Understanding Server-side Data Source
- Understanding Services Data Source
- Understanding Client-side Data Source
- Best Practices and Key Scenarios
Understanding Server-side Data Source
This data source type enables you to continue using server-side data source in WebCombo. Supported server-side data source are:
- Datasource controls, such as AccessDataSource, LinqDataSource, ObjectDataSource, etc.
- Datasource object, which is assigned in InitializeDataSource event (also known as Traditional Binding).
This data source type is designed to help you leverage and reuse existing infrastructure which has used server-side data source, while at the same time enables you to take advantage of many client binding benefits such as improved performance and reduced data footprint.
To learn the difference between server-side binding mode and client-side binding mode with server-side datasource type, please see The Differences with Server-side Binding.
Server-side data source type is the quickest and easiest way to take advantage of client-side binding. You don’t need to create web service or data service as WebGrid seamlessly connects to server-side data source for data retrieval, which is then repackaged into lightweight format for further processing in the client-side.
Understanding Services Data Source
This section describes the service type supported in WebCombo, and explains the techniques to work with the data services using the provided LINQ data provider. The service events is also discussed in this section.
Service Types
Web Service
WebService data source type enables you to connect WebCombo to a web service in elegant fashion, which is done through properties configuration without requiring you to write Javascript code. To connect WebCombo to a web service, simply specify the service address in the provided ServiceUrl property and the web method used to retrieve data in the SelectMethod property.
WebService will automatically activate full client-side operation mode when your data service returns all data. It also supports paged data retrieval for optimized performance. By default, WebCombo is operating in paged data mode when using services data source.
WebService fully supports data transaction operations such as insert, update, and delete. It also supports more advanced operation such as batch update.
The following example shows the WebCombo markup declaration that uses WebService service type.
Copy Code | |
---|---|
<ISWebCombo:WebCombo ID="wcCountry" runat="server" UseDefaultStyle="True" Width="150px" Height="20px" DataTextField="CountryName" DataValueField="Country_Id" BindingOperationMode="ClientBinding"> <LayoutSettings EntryMode="AutoComplete"/> <ClientBindingSettings DataSourceType="WebService" ServiceUrl="WebCombo_WebService.asmx"> <ServiceMethods SelectMethod="GetCountries" /> </ClientBindingSettings> </ISWebCombo:WebCombo> |
Your web service should have the capability to return output in JSON format since client binding accepts data only in JSON format. If you are developing the web service in ASP.NET 3.5, this indicates that your web services have supported JSON response format. |
Windows Communication Foundation (WCF) Service
WcfService data source type enables you to connect a WebCombo to a Windows Communication Foundation service in an elegant fashion, which is done through properties configuration without requiring you to write Javascript code.
To connect WebCombo to a WCF service, simply specify the service address in the provided ServiceUrl property and the web method used to retrieve data in the SelectMethod property.
Copy Code | |
---|---|
<ISWebCombo:WebCombo ID="wcCountry" runat="server" UseDefaultStyle="True" Width="150px" Height="20px" DataTextField="CountryName" DataValueField="Country_Id" BindingOperationMode="ClientBinding"> <LayoutSettings EntryMode="AutoComplete"/> <ClientBindingSettings DataSourceType="WcfService" ServiceUrl="WebCombo_WcfService.svc"> <ServiceMethods SelectMethod="GetCountries" /> </ClientBindingSettings> </ISWebCombo:WebCombo> |
Your WCF service should have the capability to return output in JSON format since client binding accepts data only in JSON format. If you are developing the WCF services in ASP.NET 3.5, this indicates that your WCF services have supported JSON response format. |
ADO Data Service
ADO Data Service is Microsoft’s latest data service technology introduced in .NET Framework 3.5 SP1. It enables data to be consumed programmatically through standard Web protocols such as REST, XML, SOAP and JSON. To learn more about ADO Data Service, please visit ADO.NET Data Service Home.
Intersoft’s ClientBinding is the industry's first client-side framework that implements full support for this latest technology. To connect a WebCombo to a ADO.NET data service, all you need to do is specifying the service address in the provided ServiceUrl property.
ADO Data Service enables programmatic data access over the Web with very minimal effort, which includes support for sorting, filtering and paging. It also includes native support for data transactions such as insert, update, delete, as well as more advanced operation such as batch update.
ClientBinding fully takes advantage of ADO Data Service's capabilities and implement direct interface to access its functionality. As the results, you are not required to specify any of the service methods.
The following example shows a simple declarative markup to enable all data operations.
ASPX | Copy Code |
---|---|
<ISWebCombo:WebCombo ID="wcProducts" runat="server" UseDefaultStyle="True" Width="150px" Height="20px" DataTextField="ProductName" DataValueField="ProductID" DataMember="Products" BindingOperationMode="ClientBinding"> <ClientBindingSettings DataSourceType="AdoDataService" ServiceUrl="NorthwindDataService.svc" /> </ISWebCombo:WebCombo> |
Service Handlers
In server-side binding mode, WebCombo handles the search query automatically based on the provided data source. This means that developers simply need to pass the data source and WebCombo will process all the data operations such as data lookup, filtering and adding. It is also possible to customize the data operations by using load-on-demand technique.
In contrast, the client-side binding mode would require you to handle the data retrieval process in the service handler and return the required data shape to be passed to the WebCombo. This process is by design because WebCombo is no longer processing data operations in the server-side.
For the best performance, it is recommended that the paging is processed in the data service during data retrieval. The following section explains about the possible techniques to achieve such implementation.
Using LINQ to Query Data
Intersoft’s ClientBinding™ introduces an elegant solution that enables you to easily retrieve paged data in your data service. ClientBinding encapsulates essential select arguments into an object called DataSourceSelectArguments. This object is always passed to the parameter of your Select method, enabling you to easily perform data selection based on the given information.
When a data operation, such as sorting and filtering, is required; WebCombo will send a request to the specified data service by including the complete request data in the selectArguments parameter. You are responsible to handle the sorting, filtering and paging based on the select arguments. In addition, WebCombo will also send a SelectCount request when it needs to invalidate the paging status.
DataSourceSelectArguments class contains the following properties:
- FilterExpression. The string of filter expression based on ADO.NET syntax.
- SortExpression. The string of sort expression based on ADO.NETsyntax.
- MaximumRows. The number of maximum rows to be retrieved.
- OperationType. The type of the operation for this request.
- StartRowIndex. The start index of the row to be retrieved.
- ViewName. The view name or table name to be selected.
- RetrieveTotalCount. Specifies whether the results should include total count of the query.
- Tag. Custom information passed from client-side.
Additionally, a GetLinqFilterExpression method is provided to convert ADO.NET filter expression into LINQ-compatible filter expression. This method is specifically useful for data services that use LINQ to retrieve data.
The DataSourceSelectArguments for the WCF Service counterpart is also provided, named WcfDataSourceSelectArguments. The WcfDataSourceSelectArguments is implemented in ISNet.Data.Linq assembly. |
The Select method of your Web services should return a QueryResult object, which contains the following properties:
- Results. The returned data source in IEnumerable type.
- Tag. Custom information to pass to the client-side.
- TotalRowCount. The total row count of the query.
The following C# sample shows how to handle data retrieval using LINQ in a Web service.
C# | Copy Code |
---|---|
[WebMethod] public QueryResult GetCustomers(DataSourceSelectArguments selectArguments) { QueryResult result = new QueryResult(); NorthwindDataContext context = new NorthwindDataContext(); context.DeferredLoadingEnabled = false; var pagedData = context.Customers.AsQueryable(); // handle filtering if (!string.IsNullOrEmpty(selectArguments.FilterExpression)) pagedData = pagedData.Where(selectArguments.GetLinqFilterExpression()); // handle total count if (selectArguments.RetrieveTotalCount) result.TotalRowCount = pagedData.Count(); if (selectArguments.OperationType == SelectOperation.SelectData) { if (selectArguments.StartRowIndex > -1) pagedData = pagedData.Skip(selectArguments.StartRowIndex); if (selectArguments.StartRowIndex == -1) selectArguments.StartRowIndex = 0; pagedData = pagedData.Take(selectArguments.MaximumRows - selectArguments.StartRowIndex); result.Results = dataSource.ToList(); } return result; } |
Using WebCombo LINQ Data Provider
In the above section, you have learned how to retrieve data using LINQ by manually parsing the provided select arguments. WebCombo 5 also includes WebComboDataProvider, a new LINQ data provider to help simplifying and automating the data retrieval process. You can use WebComboDataProvider in both Web and WCF services.
By using the generic WebComboDataProvider class, you can easily perform data retrieval in just a few line of code. The WebComboDataProvider automatically handle the data retrieval, filtering, total count, paging, and other operations that maybe supported in the select arguments.
The WebComboDataProvider is implemented in the ISNet.Data.Linq assembly which can be found in the WebUI Framework installation folder.
The following C# sample shows how to handle data retrieval using WebCombo LINQ data provider in a Web service.
C# | Copy Code |
---|---|
[WebMethod] public QueryResult GetSuppliers(DataSourceSelectArguments selectArguments) { NorthwindDataContext context = new NorthwindDataContext(); context.DeferredLoadingEnabled = false; context.ObjectTrackingEnabled = false; WebComboDataProvider<Supplier> query = new WebComboDataProvider(context.Suppliers); return query.Select(selectArguments); } |
The following C# sample shows how to handle data retrieval using WebCombo LINQ data provider in a WCF service.
C# | Copy Code |
---|---|
[OperationContract] [ServiceKnownType(typeof(List<Supplier>))] public QueryResult GetSuppliers(WcfDataSourceSelectArguments selectArguments) { NorthwindDataContext context = new NorthwindDataContext(); context.DeferredLoadingEnabled = false; context.ObjectTrackingEnabled = false; WebComboDataProvider<Supplier> query = new WebComboDataProvider<Supplier>(context.Suppliers); return query.Select(selectArguments); } |
The OperationContract and ServiceKnownType attributes are mandatory in the methods that return the QueryResult object. |
Service Events
All data operations in the data service are powered with a solid, provider-based architecture that is highly extensible.
Client data services that supported by WebCombo such as WebService, WcfService and AstoriaDataSource are derived from the same data provider base. As the results, these data services share the same process life cycle, events and behaviors.
Client data services support the following events:
- Selecting. Invoked when the data provider is about to perform data selection.
- Selected. Invoked after the data provider has successfully selecting data.
- Updating. Invoked when the data provider is about to perform data update.
- Updated. Invoked after the data provider has successfully updating data.
- Inserting. Invoked when the data provider is about to perform data insert.
- Inserted. Invoked after the data provider has successfully inserting data.
- Deleting. Invoked when the data provider is about to perform data delete.
- Deleted. Invoked after the data provider has successfully deleting data.
- BatchUpdating. Invoked when the data provider is about to perform batch update
- BatchUpdated. Invoked after the data provider has successfully perform batch update.
Each operation includes pre and post events for more extensive customization. The pre events such as Selecting can be cancelled with a return false statement.
These service events are available in ServiceEvents object which is located in the ClientBindingSettings property of WebCombo.
Understanding Client-side Data Source
Client data source type allows you to assign a completely custom data source in the client-side. When this type is used, WebCombo will not request data source from services.
This type is specifically useful when you need to retrieve datasource from external sites or data services that are not supported in Intersoft’s ClientBinding. For examples, consider a scenario where you want to fetch data from an external site manually in the client-side, then pass the results to the WebCombo.
Pure client-side binding takes as little as three lines of code, such as shown in the following:
Javascript | Copy Code |
---|---|
combo.SetDataSource(dataSource); combo.DataBind(); combo.Render(); |
WebCombo accepts ISDataSet, ISDataTable or any array-based collection as data source. For more information about client binding API, please see Client Binding API.
Best Practices and Key Scenarios
This section discusses the consideration for using client binding mode in your applications, as well as provides information about the best practices for a number of common scenarios.
Although client binding offers numerous benefits, it doesn’t always fit all scenarios. If your application is running locally in corporate network or on fast broadband network, and that your application doesn’t require a service-based data source, you may consider to stay with server binding mode.
Likewise, if your end users run on thin-client with slightly limited resources, or slower terminal – client binding might not be suitable as client binding performs all operations – such as populating data, formatting, sorting, filtering, grouping, paging and more – entirely in the client side.
Client binding is generally ideal with paged data loading mode, which balances the workload between server and client side.
The following sections describe the best practices for a number of key scenarios.
Best practice #1 – Using ServerDataSource with Paging Enabled
If you are already using WebCombo control in your applications (which means server binding is used by default), you may consider using ServerDataSource mode to reuse your existing server assets and infrastructure while migrating to the client binding mode.
ServerDataSource is the mode that requires the most minimal changes to your existing code. If you don’t have post-binding processing in your code (such as in InitializeRow or InitializeCell event), the migration to client binding is nearly seamless without any significant changes.
In this case, you simply need to set DataSourceType of the ClientBindingSettings to ServerDataSource. Run your page to ensure everything is working properly.
Best practice #2 – Using WebService with Paging Enabled
If you are considering developing application that retrieves data from a data service, you can consider using WebService or WcfService depending on your server infrastructure.
To anticipate the growth of the data size returned by your data service, you can prepare your data service to return paged data instead of all data. This ensures your application to extend and scale up properly in the future.
Best practice #3 – Using AdoDataService
If you are considering to develop data service platform that is accessible over the Web from various clients such as Silverlight, WPF or Web application – you may consider developing with ADO data service.
What's New
Features Added In WebCombo 5
Client Data Binding
Client Binding API
Walkthrough
Walkthrough Topics