VoiceXML
Developing Voice XML Applications Using Microsoft.NET
Digg This!
In this fourth article in the "Spotlight on VoiceXML" series we return to our hands-on approach for developing VoiceXML applications. In Part 1 we cover the basic fundamentals of the new Microsoft .NET Framework and its components. In Part 2 we'll apply .NET technologies, particularly ASP.NET, C#, and Web Services, to build an interactive VoiceXML application.
From a developer's perspective the Microsoft .NET Framework is an environment for developing, deploying, and executing applications - traditional Windows and Web-based applications as well as dynamic Web Services. With a rich set of class libraries and the flexibility of multiple languages the .NET Framework allows developers to focus on creating application business/presentation logic and leave the "plumbing" work to the underlying framework.
The .NET Framework is currently in beta. More information is available on the .NET home page or at the MSDN Online .NET Developer Center, both at www.microsoft.com/net/.
The .NET Framework comprises the following components - runtime, class libraries, supported languages, and ASP.NET (see Table 1).
.NET Common Language Runtime
At the heart of the .NET Framework is the common language runtime (CLR). Technically speaking, the runtime represents four constituents - common type system (CTS), common language specification (CLS), virtual execution system (VES), and the underlying metadata that provides a common interchange mechanism. Basically, the runtime provides an object and type system that's common across the .NET-compatible languages and is responsible for performing all the groundwork - memory allocation, thread/process management, managing security, and more. .NET-based programs are compiled into an instruction set called Microsoft intermediate language (MSIL), which is both language- and CPU-independent. However, MSIL is not interpreted. It's converted into machine code before the programs are executed.
.NET Class Libraries
.NET class libraries are a rich, comprehensive set of classes that provide pre-built functionality to the .NET programming model. They include a class hierarchy for functionality around user interface development, Web Services, database access, networking, input/output, XML/
XSL processing, security, and more.
.NET Languages
The .NET Framework SDK (the current beta 1 version) lets you use four languages to develop .NET applications and components - C#, Visual Basic.NET, Visual C++ (with extensions), and JScript.NET. (Note: The .NET Framework allows third parties to create their own language bindings as well.)
C#
C# (pronounced C-sharp), introduced by Microsoft with .NET, is a simple, object-oriented programming language. The goal of C# is to provide developers with the power and richness of C++ and the ease and simplicity of Visual Basic. We'll use C# in Part 2 when we develop our VoiceXML application. Here's the famous "Hello World" application using C#.
using System;
public class HelloWorld
{
public static void Main()
{
String msg = "Hello World from C#";
Console.WriteLine(msg);
}
}
Visual Basic.NET
Visual Basic.NET (a.k.a. Visual Basic version 7.0) is the next major revision from Visual Basic 6.0. It now supports core object-oriented programming constructs such as inheritance, structured exception handling, overloading methods/properties/procedures, constructors and destructors, interfaces, and delegates. Visual Basic.NET now also supports the "Free Threading" Model, previously available to C++ developers only. Let's look at "Hello World" again using Visual Basic.NET.
Imports System
Module MainModule
Sub Main()
Dim msg As String
msg = "Hello World from Visual Basic.NET"
Console.WriteLine(msg)
End Sub
End Module
Visual C++
The .NET SDK/Framework provides a set of managed extensions to the C++ programming language that empowers the C++ language with a set of keywords and attributes, enabling the underlying C++ language to use a .NET component to wrap/migrate existing C++ applications to the .NET environment. The following is what our Hello World example looks like in managed C++. Notice the usage of the .NET classes String and Console. Note: The C++ compiler can be triggered to use the .NET runtime by using the "/CLR" switch; for example, cl/CLR HelloWorld.cpp would be able to compile the following program:
#using
using namespace System;
void main()
{
String *msg = L"Hello World from
Managed C++";
Console::WriteLine(msg);
}
JScript.NET
JScript.NET is an implementation of the standard ECMAScript language. It's a strongly typed programming language that provides core benefits, such as improved execution speed, strong type checking, and easy-to-read code. Let's see the how the simplicity in JScript shows up in the following JScript.NET-based application.
import System;
var msg = "Hello World from
JScript.NET";
Console.WriteLine(msg);
ASP.NET
ASP.NET is the next generation of the Active Server Pages (ASP) Web development environment for creating dynamic applications. It allows application developers to use any of the .NET-supported languages (including JScript, C#, and Visual Basic) as a scripting language within a page model. ASP.NET has major advances from ASP, including full support of .NET languages (and not just a scripting derivative), configurable session management, and the concept of server-based Web controls.
<%@ Page language="C#"
ContentType="text/html" %>
<%
Sting msg = "Hello World from ASP.NET";
%>
<%=msg%>
Web Services
A key feature of .NET is that it makes the creation of Web
Services as simple as developing a dynamic Web page. For example, the
following script creates a full-featured SOAP-based service called
HelloService with a method SayHello that returns a string message.
.NET Framework-based Web Services use Simple Object Access Protocol
(SOAP) for communication and Service Description Language (SDL) to
represent the description and metadata for a service.
<%@ WebService Language="C#"
class="SeraNova.HelloService" %>
namespace SeraNova
{
using System;
using System.Web.Services;
public class HelloService :
WebService
{
[ WebMethod ]
public String SayHello()
{
return "Hello Web Services";
}
}
}
Executing the Web Service with a browser using the URL
http://localhost/HelloService.asmx/SayHello returns the following XML:
Hello World from Web Services
The returned XML can then be processed by any application
that has XML-processing capabilities.
It's also possible to invoke the Web Service as part of
another .NET application or component, after proxy classes have been
generated for the appropriate language bindings.
using System;
public class UsingService
{
public static void Main()
{
HelloService service = new
HelloService();
String msg = service.SayHello();
Console.WriteLine(msg);
}
}
Conclusion
The .NET Framework builds on top of the popularity of ASP and
COM/DCOM-based Web applications, and is poised to become a popular
development platform for building multitier, Web-based applications
and services. In Part 2 we'll apply the various components of the
.NET Framework to create VoiceXML-based interactive applications.
References
- Microsoft .NET Home Page: www.microsoft.com/net
- MSDN Online .NET Developer Center: http://msdn.microsoft.com/net
- .NET Framework SDK Beta 1: http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/000/976/msdncompositedoc.xml
- Visual Studio.NET: http://msdn.microsoft.com/vstudio/nextgen/default.asp
- The MSDN Show:http://msdn.microsoft.com/theshow/
About Hitesh SethHitesh 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.