|The Next Step...|
|Once you complete this article, be sure to read a great follow-up: David Power's Understanding Windows Script Components! In David's article, he looks at the advantages of WSC's over server-side includes and compiled COM components. David also builds a very useful WSC component in his article and shows a unique way to instantiate the WSC components!|
This article assumes that the reader knows what COM components are and how to create them using a high-level language. If you are new to COM components, you should first read: Writing a COM Component with VisualBasic.
COM components provide several advantages over ASP. While performance increases are one advantage to using COM objects over ASP code, COM components also help encapsultate implementation complexity. For example, imagine that you had an ASP page that added a row to a database table. If this logic were embedded in the ASP page, the ASP developer would need to know the database table structure, what the various column bounds were, etc. Using a component, however, the developer only needs to set a few properties and then call a method to insert the row. This approach does not require that the ASP developer have any knowledge on the actual table structure, what column input is invalid, etc.
COM components can be created by a plethora of high-level programming languages, including VisualBASIC, Visual C++, and Java. One of the biggest disadvantages of developing COM components using one of these high-level languages is the time-intensive process of altering an existing COM component. For example, say that you are developing a COM component. You add some properties and methods and start using it on your site. Now, say that you wanted to add a new method. After adding this method you would have to recompile the COM component, reregister it, and stop and restart the Web server. (For a more detailed description of this process be sure to read: Recompiling VB Components.)
To solve for this annoyance, Microsoft has created Windows Script Components, which, as their name implies, are COM components created with script! These components can be developed with any Windows scripting language (VBScript, JScript, PerlScript, Python, etc.). Since these components use script, you can literally cut and paste your ASP script into one of these scripted components! Also, you can edit a Windows Script Component's code and the changes are automatically reflected - no recompiling, no restarting the Web server, and no reregistering the component!
To get started developing your own Windows Script Components you'll need to download the Windows Script Component Files from Microsoft's Scripting Site (freely available). While you're there, also be sure to download the Windows Script Component Wizard, which we'll be using in this article to create the skeleton to our Windows Script Component. Once you download these files, be sure to install them.
The Windows Script Component Wizard is a helpful six-step Wizard that will generate the
shell of our Windows Script Component. A Windows Script Component is a simple text file
.wsc extension. The contents of the file are an XML-formated
section containing registration information about the component, a list of the components
methods and properties, and the source code to these components and properties. The
Windows Script Component Wizard will generate all of the registration information, the
list of properties and methods, and empty functions for our component's methods. All we
need to do is fill in the code for these methods!
For this article we will create a COM component that will convert a Celcius temperature
to a Fahrenheit temperature and vice versa. The component will have no properties or
events, and two methods:
Both methods will expect one parameter (the temperature to convert from) and return to
temperatur to convert to. Granted, such a simple task could be put in a simple function
in the ASP page, but I just want to show you how to create a Windows Script Component. It
is up to you to apply it! :-)
To start creating your Windows Script Component, start up the Wizard (after it is installed
it should be in Start/Program/Microsoft Windows Script/Windows Script Wizard). In Step 1
you need to enter the registration information which includes the name of the component,
its filename, its version, and its ProgID. The ProgID is what is used to instantiate the
object in an ASP page (
Server.CreateObject(ProgID)). For our example
name the component
Temperature and give it a ProgID of
The figure below shows the values that you should enter for Step 1 of the Wizard.
In Part 2 we will look at the reamining five steps of the Wizard!