Handling Articles and Categories for an ASP.NET AJAX Client-Centric Wiki Application
(Page 1 of 4 )
In the first two articles in this series, we began building an ASP.NET client-centric wiki application. We left off with the user interface. In this article, the third one in a four-part series, we continue looking at the user interface, with a special focus on the article categories.
A
downloadable .rar file is available for this article.
Web Service and Database
First, let’s look at the definition of the Web Service—MyDataService:
using System.Data;
using System.Web.Script.Services;
using Microsoft.Web.Preview.Services;
using Demos.CategoryInfo;
…… (Omitted)
[ScriptService]
public class MyDataService : DataService{
[WebMethod]
[DataObjectMethod(DataObjectMethodType.Delete)]
public void DeleteRecord(CategoryInfo o){
if (o.CategoryName == null)
{throw new AccessViolationException();}
new SqlTaskProvider().DeleteRecord(o);
}
[WebMethod]
[DataObjectMethod(DataObjectMethodType.Select)]
public List<CategoryInfo> GetAllRecords()
{ return new SqlTaskProvider().GetAllRecords();}
[WebMethod]
[DataObjectMethod(DataObjectMethodType.Insert)]
public void InsertRecord(CategoryInfo o) {
if (o.CategoryName == null)
{ throw new AccessViolationException();}
new SqlTaskProvider().InsertRecord(o);
}
[WebMethod]
[DataObjectMethod(DataObjectMethodType.Update)]
public void UpdateRecord(CategoryInfo o) {
if (o.CategoryName == null) {
throw new AccessViolationException();
}
new SqlTaskProvider().UpdateRecord(o);
}
}
First, as required by the framework, we must put the ScriptService attribute before the Web Service so that the MS AJAX JavaScript framework will call it correctly. Second, you may have noticed that this web service doesn’t expose web methods in a typical manner. In this case, the web service is derived from DataService which exposes two special types of web methods (GetData and SaveData, you can further study them by examining the assembly Microsoft.Web.Preview.dll using the .NET object browser and Lutz Roeder's.NET Reflector tool). The methods defined here are attributed using [DataObjectMethod]. These are used by the ObjectDataSource control to expose methods that are treated as Select, Insert, Update, or Delete.
Note here in each web method we use a helper class named SqlTaskProvider that is defined inside the ‘Demos.CategoryInfo’ namespace to make the design modular. And also, the parameter type CategoryInfo is a general C# class which acts as an OOP wrapper for a record in the CategoryInfo table.
Next: Display the Article Categories >>
More ASP.NET Articles
More By Xianzhong Zhu