Top tips for developing components for ASP
Hi again have you ever developed VB components for use in Active Server Pages? If so, then you probably came up against the same problems that I did.
In this article Ill take you through the problems that Ive had and how you can get around them. If youve got any additional tips, let me know and Ill share them with the rest of the visitors to this site.
Also, if you want to say something about this article, or want to ask a question, please use the Post Feedback Now link at the bottom of every page.
Right, on with the info!
The first thing Ill do will be to give you a little background on the topic of ASP and components. ASP seems to be coming into its own right now, and many people are starting to migrate to the Windows platform to support this new technology. One of its key advantages is that you can write components in a language such as VB and use them through ASP.
A typical component might interact with a SQL Server database handling information about customers or their orders. Whatever the task, it would appear that there are a wide variety of technologies available to help you out here.
For starters, Microsoft Transaction Server enables you to pool a small amount of resources that can be shared amongst many users. You can host a VB DLL within MTS, and share SQL Server connections as required.
Next, Internet Information Server, Microsofts free web server product allows you to run your DLLs out of the IIS process, meaning that you DLL can crash but not take down the whole web server as well. IIS 5 (in Windows 2000) now supports a multitude of component pooling and looks very handy.
OK so whats useful about a component? Well, it encapsulates all the code for a specific function into one part making bug fixing and updating much easier. You can host this DLL on another machine if necessary, using DCOM to communicate with it as well as hosting it in Microsoft Transaction Server. But the real benefits of using a component come about when writing it. Using a language we all know well, VB, in an excellent design environment makes things a lot easier.
Over the next few pages I will give you a stack of tips to help you develop, debug and test such components.
If you ever used Visual Interdev, youll probably think that its great for writing ASP. IntelliSense object models popup even for custom components and the debugging tools look almost as good as the ones in VB. The reality of this is far from great. Every time you open a page that makes an instance of your DLL, Visual Interdev loads that DLL into memory to get its object model. So if you want to recompile your DLL you have to close down your page.
Thats not too much of a problem, but when you actually run the page in your browser it appears that however much you try you cant get ASP to release your DLL! This either means a complete reboot or a stop and start of IIS. Windows 2000 adds a well needed restart feature but for those of you running IIS 4 heres a little DOS batch file that will take care of restarting IIS:
@echo offNET STOP iisadmin /yMTXSTOPNET START W3SVC
Simply run that each time and IIS will be restarted, flushing all components out of memory.
The next problem that I came up against was passing parameters into my DLL. As VBScript does not support variable types, every variables is a Variant. This cause lots of problems when you pass it as a parameter to a DLL which expects a string. Instead of converting it to a string (which would be expected) it throws up a Type Mismatch error so ensure all parameters coming in are declared as Variants. This is not the case when you return, so you dont need to worry about that.
When developing the DLL, I suggest that you keep it as a standard EXE project and debug it like that. Then, when youre ready to test it with ASP, compile it as an ActiveX DLL. This way you can cut out a lot of restarting IIS.
However bad Visual Interdevs debugging features may be for components, make sure that you use whats available. Turn debugging on for your web site by loading Internet Service Manager, right clicking on your web site and selecting properties. Choose the Home Directory tab and select Configuration (under the Application Settings frame). Now select the App Debugging tab and make sure that Enable Server Side ASP Script Debugging and Enable Client Side ASP Script Debugging are checked. This will allow you to use Visual Interdev to hook onto the IIS process.
OK so youve built your nifty DLL and ASP script, but how do you know how well it will perform? Lets find out
You could ask Microsoft to put your page live on their site for testing, but I dont think they would be too pleased to do that. So, do you invite all your friends around to continually refresh your ASP page as you watch the server crash? No! You go and download the free Microsoft Web-Application Stress Tool of course.
Hidden away in a derelict part of Microsoft.com youll find the WAS. This excellent free tool allows you to hit your ASP page for days on end having detailed reports generated for you. You can find it at:http://webtool.rte.microsoft.com/ although its a fairly large download (about 9mb) so you may want to leave it to come down overnight.
Right, I best be off some more ASP components to write! In the meantime, have fun writing components for ASP (youll know what I mean when youve finished doing it, not during!) If you come across any more tips please let me know and Ill post them to this page. If youve got anything to say about this article or want to ask questions, please use the Post Feedback Now link at the bottom of this page. If you would like to send me cheques, gifts or other forms of thanks, use my email address: firstname.lastname@example.org