Windows Script Components provide VBScript and JScript developers with the ability to create COM style components. They can wrap up shared functionality into a component which can be registered on a server and instantiated using a CreateObject call just like other COM.
Defining a component
<?xml version="1.0"?>
<component>
<public>
<property name="Forename" internalName="strForename" />
<property name="Surname">
<get/>
<put/>
</property>
<method name="Save" />
</public>
<script language="VBScript">
<![CDATA[
Dim strForename, strSurname
Function get_Surname()
get_Surname = strSurname
End Function
Function put_Surname(strValue)
strSurname = strValue
End Function
Function Save()
If IsEmpty(strForename) Or IsEmpty(strSurname) Then
Save = False
Else
Save = True
End If
End Function
]]>
</script>
</component>
Usage
Set myObj = Server.CreateObject("MyApp.MyClass")
myObj.Forename = "Derek"
myObj.Surname = "Fowler"
myObj.Save()
Set myObj = Nothing
Advantages
- You don't need to server-side include anything to use them, once they're registered they're available from anywhere
- Like other COM you can use them Application or Session scoped in ASP which means you can use a tailored object rather than abusing Arrays or a Recordset to create your shopping basket
- Anywhere you can use a COM component you can use a WSC - even within a .NET application
Disadvantages
- You don't get the performance benefits of proper compiled COM components
- They don't support destructors which can make clearing up a pain
- You can't do proper locking in VBScript or JScript so it's difficult to avoid concurrancy issues such as when using them Application scoped in ASP
Having said all that for the majority of applications the advantages certainly outway the disadvantages. Creating your data access and business tiers using WSCs allow you to work outside the confines of ASP environment and create components you can use anywhere that supports COM.
For anyone working in a company that is resisting the adoption of .NET this ability to write functionality to use in ASP but which you can then reuse in ASP.NET provides you with a clear upgrade path.
