Sharing structured data

XML Magazine

Subscribe to XML Magazine: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get XML Magazine: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

XML Authors: Jason Bloomberg, Jayaram Krishnaswamy, Chris Pollach, Peter Silva, Mehdi Daoudi

Related Topics: XML Magazine

XML: Article

Developing VoiceXML Applications Using Microsoft.NET

Developing VoiceXML Applications Using Microsoft.NET

In Part 1 of this article (XML-J, Vol. 2, issue 6) we introduced the key components of the Microsoft .NET Framework - ASP.NET, C#, and Web Services. In Part 2 we apply the .NET technologies to develop an interactive VoiceXML application. Toward the end of the article we review the concept of Web Services and how it applies to the world of developing interactive voice applications.

Table 1 provides a summary of some of the key components of the .NET Framework that we utilize to develop an interactive VoiceXML application.

.NET and VoiceXML
We use the following Employee Directory scenario as our sample application, which is similar to the one we worked on in the February issue of XML-J (Vol. 2, issue 2). We also enhance the user interface to be more natural language-oriented using the grammar we developed in the May issue (Vol. 2, issue 5).

Application Scenario
First the user dials a number using a regular or cell phone. The system greets the user with a prompt, then waits for input; the user communicates with the system in almost natural language, "Please call Hitesh Seth on his mobile phone." After recognizing two important keywords from the user's input (name and phone type), the application uses Text-to-Speech (TTS) to present a system-generated voice message about the user, then transfers the call to the appropriate phone number.

The following conversation depicts the interaction between the user and the VoiceXML-based application.

  • User dials 1 (800) nnn-nnnn
  • System: Welcome to SeraNova Employee Directory. What can I do for you?
  • User: Please call Hitesh Seth on his mobile phone.
  • System: Calling Hitesh Seth on his mobile phone (732) 433-5603
  • System dials (732) 433-5603 and connects it to the user.
Application Design -
.NET in Our Application

Now we'll use essential components of the .NET Framework to model our VoiceXML-based application:
  • .NET components: They represent the object-relational database access model of the table "Employee". These components will be compiled into a dynamic link library (DLL) that's referenced by the ASP.NET Pages IIS Web Server and served through the IIS Web Server. (Typically, the DLLs are kept in the bin directory under the application root directory under IIS.) As we'll see later, .NET provides a platform for creating distributed Web Services that allow further partitioning of Web applications.
  • Set of ASP.NET pages: Collectively present a VoiceXML interface to a VoiceXML gateway.
Figure 1 shows the .NET Framework-based design of the employee directory application.

On the database side we have a relational database table Employee (Primary key - ID, other fields - name, e-mail, direct, cellular).

Employee Class
The Employee class represents an object model of the database table "Employee". Listing 1 shows the complete implementation of the Employee class using C#. Essentially, the class has one-to-one mapping of the fields in the Employee table as properties. This class is used by the employee business object to represent the employee entity.

Employee Business Object
A key component of our application is the employee business object. This object provides two methods - GetEmployee, which retrieves a particular employee's information, and GetEmployees, which returns a collection of employee objects. Listing 2 shows the implementation of the employee business object in C#. Alternatively, the employee business object can also be implemented in a different .NET-supported language such as Visual Basic.NET. Listing 3 shows a simple build script that can be used to compile the .NET component using the .NET C# language compiler (csc.exe).

Dynamic Web Scripting

Now we use ASP.NET-based technology to query the object and present a VoiceXML user interface to the VoiceXML gateway. It's possible to have just one single ASP.NET page that generates the complete VoiceXML user interface. However, since an actual employee directory may consist of hundreds to thousands of employees, we split the script into three different pages - EmployeeDirectory.aspx (see Listing 4), Grammar.aspx (see Listing 5), and Employee.aspx (see Listing 6) - as shown in Figure 2.

The EmployeeDirectory.aspx page serves as the entry point to the VoiceXML gateway, with the grammar for the input represented by the page Grammar.aspx. When requested by the main application, the Employee.aspx page performs a lookup on a particular employee (based on ID) and forwards to the appropriate telephone number (mobile or direct).

The Grammar.aspx invokes the GetEmployees method of the employee business object and then iterates through the collection to create a grammar that matches all the employees in the possible utterances.

After the utterance is recognized by the speech recognition engine, the VoiceXML interpreter invokes the Employee.aspx page that decodes the input parameter cmd (encoded as <id>, <phone-type> e.g. 1,mobile), looks up the appropriate employee object, and presents the related employee information in a VoiceXML block (see Listing 6).

Web Services
Perceived by some as the fourth wave of computing, Web Services take the Web application model to the next level. Instead of the Web being applied to the traditional HTML-based information exchange, Web Services set the Web up to be a dynamic service bureau publishing a directory of collaborative IP-based services. Technically speaking, a Web service is essentially an XML request/ response-based interaction model for creating distributed applications. Web Services utilizes established Web protocols such as HTTP/HTTPS and facilitates the creation of loosely coupled and distributed IP-based services.

Web Services can also be used to create a loosely coupled distributed computing environment for the division of work/logic/computing power instead of (or along with) the traditional Remote Procedure Call-based, distributed objectbased distribution mechanism. For instance, the application tier can be conceived as a collection of Web Services connected with the presentation tier using HTTP/SOAP.

Let's see how Web Services apply here. We can remodel the employee business object of our application as a simple Web service called employee service. This service has two methods, GetEmployee and GetEmployees, that return data sets containing a particular employee by ID and all the directories of all the employees, respectively. Listing 7 shows the complete employee service.

An invocation of the Web service's methods, followed by a transformation with appropriate XSLT-based stylesheets, can then drive the delivery of our VoiceXML-based application (represented in Figure 3). Listing 8 provides a sample XML returned by invocation of the GetEmployees method on the EmployeeService (by invoking the URL http://localhost/EmployeeService.asmx/GetEmployees).

XML/XSLT transformation can be achieved by calling XslTransform directly:

<%@ Page language="C#" ContentType="text/xml" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
XslTransform xslt = new XslTransform();
XmlDocument xml = new XmlDocument();
xslt.Transform(new Document

or by using the <asp:xml> server-side control as:

<%@ Page language="C#" ContentType=
"text/xml" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
XmlDocument xml = new XmlDocument();
xslt.Document = xml;
<asp:xml id="xslt" TransformSource=
"EmployeeDirectory.xsl" runat=server/>

The .NET Framework provides developers with a lot of flexibility by allowing them to use a wide variety of programming languages. Even a simple scenario such as this brings out the advantages of the loosely coupled Web Services application model.


  1. Microsoft .NET Home Page:
  2. SOAP 1.1:
  3. XSLT Specification:

More Stories By Hitesh Seth

Hitesh Seth is chief technology officer of ikigo, Inc., a provider of XML-based web-services monitoring and management software. A freelance writer and well-known speaker, he regularly writes for technology publications on VoiceXML, Web Services, J2EE and Microsoft .NET, Wireless Computing & Enterprise/B2B Integration. He is the conference chair for VoiceXML Planet Conference & Expo.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.