Script
We should consider the necessity of using ASP script components in our work from both pros and cons. Compared to compiled components, the ASP Script component has an obvious feature: The WSC script file can be edited at any time, and the changes in the component can be reflected automatically the next time it is executed. You do not need to recompile, you do not have to restart the server to release references to existing components, and you do not need to re-register. Also, if the component works well, you can use the appropriate language to create a compiled version with proven code and/or algorithms, which is also true for any convertible component.
ASP script components are adaptable to COM +. In fact, like other ASP built-in objects, this component accesses the ObjectContext object. Therefore, SetAbort and SetComplete can be used at any time if necessary.
Script components can be packaged with existing business objects (components) using standard COM interfaces, even if they are written in Perl. In the packaging process, you do not have to know how to write in Perl, do not need to know the relevant knowledge. The language-neutral nature of COM makes interoperability easier.
The component of the code not only improves the performance of the Web site, but also helps you design and maintain the Web site by re using common code blocks.
Enabling WSC pages is better than using a server-side containing (server-side Include,ssi) file. Although they do the same thing, the ASP Script component can dynamically create the desired object based on the run-time condition or input parameters. SSI does not allow dynamic selection, allowing only files that are hard-coded in the source code of the page to be imported.
Of course, there are some drawbacks to ASP script components:
? Interpretation components do not have the ability to compile components, so the performance of ASP script components is not necessarily optimal. But performance is not the reason to use them.
? ASP scripting components do not have access to the full Win32 API, and a system-level task requires a specific COM automation object. Also, scripting languages are not a very mature language compared to C + +, even with VBA.
16.6.1 Choose the right tool
Here's a quick way to choose the right tool when creating an ASP component.
To develop critical and real-time components that require the highest server performance, you should use Visual C + +.
Because most server-side components perform tasks for data access classes, consider using C + + and the original OLE DB calls for maximum performance. The combination of Visual C + +, alt templates, and OLE DB interfaces may be most effective for performance improvement. The next chapter of this book will be more descriptive of the C + + development component.
Visual Basic is also a powerful tool for developing components. If you are developing a component that is not critical, you can use visual Basic. In addition to the same compilation code, full win 32 access, and component instantiation, Visual Basic is easier than Visual C + +.
WSC enables the original code of the page to be component-based, and creating a script object from COM adds some extra effort, but is more flexible and reusable, and reduces maintenance effort.
Comparison of 16.6.2 script components and VBScript classes
If you plan to use VBScript 5.0 in an ASP component, consider using a VBScript class instead of a script component.
Create a VBScript analogy it takes less time to create a Windows Script component because unlike CreateObject, new does not need to locate the mounted file through the COM engine and registry. The programming capabilities of both are almost the same, but using WSC can take advantage of the different scripting languages.
16.7 Summary
This chapter analyzes the Windows Scripting Component (WSC) technology, which is a special case of ASP scripting components. Writing COM objects in a scripting language is not difficult to implement, in fact, it has many advantages. But this chapter doesn't fit every situation, so it doesn't solve all the problems that are actually encountered.
The contents of this chapter are summarized as follows:
? The structure of the WSC and the role of the interface processor.
? The mapping of ASP built-in objects in page scripting code.
? Interaction between the client and ASP script components.
? A complete WSC example for ASP pages.
? Advantages and disadvantages of ASP script objects.
The next chapter describes how to write powerful components using Visual C + +.