Debugging Active Server Objects As you saw in the previous section, Active Server Objects are like ISAPI DLLs: After they are loaded, you need to bring down the entire Web server to unload them because Active Server Objects are loaded by the ASP.DLL , which is an ISAPI DLL in itself. However, the advantage of ASP is the fact that for the Active Server Pages themselves, you can update the scripts as much as you want, without having to change, unload, or reload the Active Server Objects themselves. As long as the functionality inside the Active Server Object doesn’t change, you need only to update the scripts. Of course, making sure that the Active Server Objects work correctly is another task, which at times requires the capability to debug Active Server Objects. When it comes to debugging Active Server Objects, a few things can be done right away, such as showing a simple message box or using a debug window to show strings sent from the Active Server Object. In order to get any of these messages, however, you must first specify that the owner of the Active Server Object is indeed qualified to interact with the desktop. Specifically, for the IIS Admin Service, set the Interact with Desktop option in the Services applet (dialog box) of the Control Panel Services dialog box, as shown in Figure 22.14. ASP Development CHAPTER 22 22 ASP DEVELOPMENT 1071 FIGURE 22.14 Allow Service to interact with Desktop. After you’ve specified that option, you can use almost any means to have your Active Server Objects interact with the desktop. This is still a bit crude, but it can be effective enough at times. Debugging Active Server Objects with MTS There is an easier way to manage your Active Server Objects, which also greatly improves your abilities to actually debug Active Server Objects written in Delphi (or C++Builder for that matter). The solution, as the title of this section indicates, involves MTS as host for your Active Server Object.The first step involves unregistering the Active Server Object you’ve written in this chapter. This can be done by choosing Run, Unregister ActiveX Server from the Delphi 6 menu. After the Active Server Object has been successfully unregistered, you can register it again, but this time as an MTS Object. To do this, choose Run, Install MTS Objects. (On Windows 2000, this menu option will be called Install COM+ Object.) The resulting dialog box appears in Figure 22.15. Internet Development PART VI 1072 FIGURE 22.15 Install MTS (or COM+) Objects. In this Install MTS Objects dialog box, select your DrBob42 object by clicking on the check box. This will result in the pop-up dialog box shown in Figure 22.16, which asks for a package name to install the DrBob42 object into. You can either select an existing package, or specify a new package such as DelphiDebugPackage : The COM+ dialog box works in a similar way on Windows 2000. FIGURE 22.16 Install Object DelphiDebugPackage . Now, click OK in the Install Object dialog box and click OK again in the Install MTS Objects dialog box. After having installed the DrBob42 object as an MTS object, you can debug the Active Server Object from within the Delphi IDE itself. For this, you need a host application in order to load the Active Server Object. The steps you must take from this point on differ in Windows NTand Windows 2000. First, I’ll show you the steps for Windows NT, followed by the steps for Windows 2000. Debugging Using Windows NT 4 For Windows NT with the Option Pack installed, you need to specify MTS as the Host Application. MTS will already be running, so you must shut it down first. ASP Development CHAPTER 22 22 ASP DEVELOPMENT 1073 As a consequence, you should never try to do this on a real production machine. Only use a development machine in which you can afford to shut down MTS from time to time (when debugging your Active Server Objects that are hosted inside MTS). CAUTION In order to shut down MTS, you must start the Internet Service Manager application, which is part of the Windows NT 4 Option Pack. Open the Microsoft Transaction Server node in the treeview until you see Packages Installed under My Computer (which includes the DelphiDebugPackage you just installed). If you right-click on the My Computer icon, you can shut down all server processes (see Figure 22.17). This won’t give you any feedback. You can verify the shutdown by looking at the Processes list of the Windows NT Task Manager. It shouldn’t list mtx.exe anymore. FIGURE 22.17 Shutdown server processes.
Now all you have to do is specify MTS as the Host Application inside the Delphi 6 Run Parameters dialog box, so you can use MTS as host for your DrBob42 Active Server Object. On my NT 4 machine, that’s c:\winnt \system32 \mtx.exe . You must also specify the package that contains your DrBob42 object using the /p:”DelphiDebugPackage ”parameter. In this case, the DrBob42 object is DelphiDebugPackage . Specifying the package brings up a dialog box similar to that shown in Figure 22.18. Internet Development PART VI 1074 FIGURE 22.18 Run Parameters dialog box. Now, set a breakpoint in your code by clicking in the left-side gutter or pressing F5 while your cursor is on a line of code and press F9 to run and debug your DrBob42 Active Server Object as hosted inside MTS. Nothing will happen because MTS is running, but your Active Server Object has not been invoked by a browser call yet. You must now restart Internet Explorer (or another browser) and load the DrBob42.asp Web page that will load the Active Server Object. This will trigger the breakpoint: At which time, you’re able to use the Delphi integrated debug-ger on your Active Server Object. In order to end the Delphi debug session, you have to shut down MTS again (just as you did when you started to debug using MTS). Debugging Using Windows 2000 Using Windows 2000, you can no longer use mtx.exe simply because under Windows 2000, MTS is integrated into the operating system. However, you can use dllhost.exe to load the ProcessID of your Active Server Object. This technique will also work on Windows NT. but, it is slightly more complex, which is why I first showed you how to debug using MTS as the Host Application under Windows NT. You should now use dllhost.exe as the Host Application, which can be specified in the Run, Parameters dialog box. The parameter should be the ProcessID of the DelphiDebugPackage containing your DrBob42 Active Server Object. You can obtain this information using theInternet Service Manager (Microsoft Management Console) on Windows NT or the Component Services on Windows 2000. The Package ID of the DelphiDebugPackage in this example is {50AE66A2-349B-11D5- A9F0-005056995CC9}. This ID can be copied from the text label of the Run Properties dialog box shown in Figure 22.19. This is the most convenient way to copy it because you probably don’t want to type it in yourself. Figure 22.20 shows the Run Parameters dialog box with the ID pasted into the Parameters text box. ASP Development CHAPTER 22 22 ASP DEVELOPMENT 1075 FIGURE 22.19 DelphiDebugPackage Package ID. FIGURE 22.20 Run Parameters with ID inserted. Now, make sure to set a breakpoint and press F9 to run (and debug) your DrBob42 Active Server Object. Similar to the previous example, nothing will happen until the ASP object is invoked through a browser. You must restart Internet Explorer (or another browser) and loadthe DrBob42.asp Web page that will in turn load the Active Server Object. This will trigger the breakpoint; at which time, you’re able to use the Delphi integrated debugger on your Active Server Object. Note that in order to end the Delphi debug session, you have to shut down DelphiDebug Package inside MTS again (just as you did when you started to debug using MTS). Summary In this chapter, you have learned what Active Server Pages are, what role Active Server Objects play in them, and how Delphi 6 can be used to write these Active Server Objects. You’ve also seen how you can use internal objects (like Request and Response), how you can add database processing to your Active Server Objects, how you can combine Active Server Objects and NetCLX components, and finally how to debug Active Server Objects with Delphi 6 under Windows NT or Windows 2000. Internet Development PART VI 1076
若设计通过,绝对给分。
As you saw in the previous section, Active Server Objects are like ISAPI DLLs: After they are
loaded, you need to bring down the entire Web server to unload them because Active Server
Objects are loaded by the ASP.DLL , which is an ISAPI DLL in itself. However, the advantage
of ASP is the fact that for the Active Server Pages themselves, you can update the scripts as
much as you want, without having to change, unload, or reload the Active Server Objects
themselves. As long as the functionality inside the Active Server Object doesn’t change, you
need only to update the scripts. Of course, making sure that the Active Server Objects work
correctly is another task, which at times requires the capability to debug Active Server Objects.
When it comes to debugging Active Server Objects, a few things can be done right away, such
as showing a simple message box or using a debug window to show strings sent from the
Active Server Object. In order to get any of these messages, however, you must first specify
that the owner of the Active Server Object is indeed qualified to interact with the desktop.
Specifically, for the IIS Admin Service, set the Interact with Desktop option in the Services
applet (dialog box) of the Control Panel Services dialog box, as shown in Figure 22.14.
ASP Development
CHAPTER 22
22
ASP
DEVELOPMENT
1071
FIGURE 22.14
Allow Service to interact with Desktop.
After you’ve specified that option, you can use almost any means to have your Active Server
Objects interact with the desktop. This is still a bit crude, but it can be effective enough at
times.
Debugging Active Server Objects with MTS
There is an easier way to manage your Active Server Objects, which also greatly improves
your abilities to actually debug Active Server Objects written in Delphi (or C++Builder for that
matter). The solution, as the title of this section indicates, involves MTS as host for your
Active Server Object.The first step involves unregistering the Active Server Object you’ve written in this chapter.
This can be done by choosing Run, Unregister ActiveX Server from the Delphi 6 menu.
After the Active Server Object has been successfully unregistered, you can register it again, but
this time as an MTS Object. To do this, choose Run, Install MTS Objects. (On Windows 2000,
this menu option will be called Install COM+ Object.) The resulting dialog box appears in
Figure 22.15.
Internet Development
PART VI
1072
FIGURE 22.15
Install MTS (or COM+) Objects.
In this Install MTS Objects dialog box, select your DrBob42 object by clicking on the check
box. This will result in the pop-up dialog box shown in Figure 22.16, which asks for a package
name to install the DrBob42 object into. You can either select an existing package, or specify a
new package such as DelphiDebugPackage : The COM+ dialog box works in a similar way on
Windows 2000.
FIGURE 22.16
Install Object DelphiDebugPackage .
Now, click OK in the Install Object dialog box and click OK again in the Install MTS Objects
dialog box.
After having installed the DrBob42 object as an MTS object, you can debug the Active Server
Object from within the Delphi IDE itself. For this, you need a host application in order to load
the Active Server Object. The steps you must take from this point on differ in Windows NTand Windows 2000. First, I’ll show you the steps for Windows NT, followed by the steps for
Windows 2000.
Debugging Using Windows NT 4
For Windows NT with the Option Pack installed, you need to specify MTS as the Host
Application. MTS will already be running, so you must shut it down first.
ASP Development
CHAPTER 22
22
ASP
DEVELOPMENT
1073
As a consequence, you should never try to do this on a real production machine. Only
use a development machine in which you can afford to shut down MTS from time to
time (when debugging your Active Server Objects that are hosted inside MTS).
CAUTION
In order to shut down MTS, you must start the Internet Service Manager application, which is
part of the Windows NT 4 Option Pack. Open the Microsoft Transaction Server node in the
treeview until you see Packages Installed under My Computer (which includes the
DelphiDebugPackage you just installed).
If you right-click on the My Computer icon, you can shut down all server processes (see
Figure 22.17). This won’t give you any feedback. You can verify the shutdown by looking at
the Processes list of the Windows NT Task Manager. It shouldn’t list mtx.exe anymore.
FIGURE 22.17
Shutdown server processes.
Parameters dialog box, so you can use MTS as host for your DrBob42 Active Server Object. On
my NT 4 machine, that’s c:\winnt \system32 \mtx.exe . You must also specify the package that
contains your DrBob42 object using the /p:”DelphiDebugPackage ”parameter. In this case, the
DrBob42 object is DelphiDebugPackage . Specifying the package brings up a dialog box similar
to that shown in Figure 22.18.
Internet Development
PART VI
1074
FIGURE 22.18
Run Parameters dialog box.
Now, set a breakpoint in your code by clicking in the left-side gutter or pressing F5 while your
cursor is on a line of code and press F9 to run and debug your DrBob42 Active Server Object as
hosted inside MTS. Nothing will happen because MTS is running, but your Active Server
Object has not been invoked by a browser call yet. You must now restart Internet Explorer (or
another browser) and load the DrBob42.asp Web page that will load the Active Server Object.
This will trigger the breakpoint: At which time, you’re able to use the Delphi integrated debug-ger
on your Active Server Object.
In order to end the Delphi debug session, you have to shut down MTS again (just as you did
when you started to debug using MTS).
Debugging Using Windows 2000
Using Windows 2000, you can no longer use mtx.exe simply because under Windows 2000,
MTS is integrated into the operating system. However, you can use dllhost.exe to load the
ProcessID of your Active Server Object. This technique will also work on Windows NT. but, it
is slightly more complex, which is why I first showed you how to debug using MTS as the
Host Application under Windows NT.
You should now use dllhost.exe as the Host Application, which can be specified in the Run,
Parameters dialog box. The parameter should be the ProcessID of the DelphiDebugPackage
containing your DrBob42 Active Server Object. You can obtain this information using theInternet Service Manager (Microsoft Management Console) on Windows NT or the
Component Services on Windows 2000.
The Package ID of the DelphiDebugPackage in this example is {50AE66A2-349B-11D5-
A9F0-005056995CC9}. This ID can be copied from the text label of the Run Properties dialog
box shown in Figure 22.19. This is the most convenient way to copy it because you probably
don’t want to type it in yourself. Figure 22.20 shows the Run Parameters dialog box with the
ID pasted into the Parameters text box.
ASP Development
CHAPTER 22
22
ASP
DEVELOPMENT
1075
FIGURE 22.19
DelphiDebugPackage Package ID.
FIGURE 22.20
Run Parameters with ID inserted.
Now, make sure to set a breakpoint and press F9 to run (and debug) your DrBob42 Active
Server Object. Similar to the previous example, nothing will happen until the ASP object is
invoked through a browser. You must restart Internet Explorer (or another browser) and loadthe DrBob42.asp Web page that will in turn load the Active Server Object. This will trigger the
breakpoint; at which time, you’re able to use the Delphi integrated debugger on your Active
Server Object.
Note that in order to end the Delphi debug session, you have to shut down DelphiDebug
Package inside MTS again (just as you did when you started to debug using MTS).
Summary
In this chapter, you have learned what Active Server Pages are, what role Active Server Objects
play in them, and how Delphi 6 can be used to write these Active Server Objects. You’ve also
seen how you can use internal objects (like Request and Response), how you can add database
processing to your Active Server Objects, how you can combine Active Server Objects and
NetCLX components, and finally how to debug Active Server Objects with Delphi 6 under
Windows NT or Windows 2000.
Internet Development
PART VI
1076
最大的麻烦是pws虽然停止服务,却没释放自己的进程,导致dll也不被放出内存。
用vc6带的pview95看系统进程,看到inetinfo.exe了?kill掉它就行了,不用重新启动机器了。呵呵。
如果ie报说外部对象产生一个可捕捉的异常,导致asp0115,8000ffff错误,基本上都是dll里有问题。
把这篇带图跟我发过来得了!EMAIL:[email protected]