p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_components thread: Ask about COM+


Message #1 by "Nguyen Anh Tuan" <tuancan@y...> on Wed, 12 Jun 2002 03:50:35
Dear Sir/Madam

Please give an answer to me about something of COM+.
I have an application on Visual Basic and base on COM technology. And now 
I want to convert my application to base on COM+. The following is what I 
have done:
1 - Add reference "COM+ Services Type Library" to the COM project.
2 - In General Declarations code, I type:
	Option Explicit
	Implements ObjectControl
3 - Implement following 3 Subs and Function:
	Private Sub ObjectControl_Activate()
	    Msgbox "Message of Start Activate"
	End Sub

	Private Function ObjectControl_CanBePooled() As Boolean
	    ObjectControl_CanBePooled = False
	End Function

	Private Sub ObjectControl_Deactivate()
	    Msgbox "Message of End Activate"
	End Sub
	
	Public Sub Show_msgbox()
	    Msgbox "Message of Show_msgbox method"	
	End Sub
4 - I save this project with project name is Prj_com and class name is 
Cls_com. After that I  make .dll file, everything is OK.
5 - Use Components Sevices tools to install this COM.
6 - Create an .ASP file with following code:
	<%	
           Set myObj = Server.CreateObject("Prj_com .Cls_com")
	   myObj.Show_msgbox	
	%>
7 - Create a Vitual directory on IIS Web server to run this .ASP file.
8 - Run this .ASP file on web browser and I see the message of "Message of 
Show_msgbox method" is appear.

As me know, in this project I used ObjectContext, so when I call any 
method in this COM, then the message of "Message of Start Activate" will 
be call first, but I did not see that. Please give me a lead how to create 
the COM+ project.

Best regards,
Message #2 by "Imar Spaanjaars" <Imar@S...> on Thu, 13 Jun 2002 19:39:24
You're missing a very important point here. You are creating a website in 
a client-server environment. In such a context, a Message Box does not 
make sense.
Who's going to click the OK button on the server after each request? You?

So you can't use server side message boxes. Your COM+ methods should 
return certain datatypes, like strings, recordsets, booleans etc. Then an 
ASP page can process the return values of the COM+ methods, and if 
necessary, create a CLIENT-side message box with JavaScript for example.

So, you should do something like this:

' VB
Public Function Show_msgbox() as String
   Show_msgbox = "Hello from Show_msgbox"
End Sub


' ASP-Page:
objTest 
Dim sMessage
Set objTest = Server.CreateObject("MyProjectName.MyClassName")
sMessage = objTest.Show_msgbox

Response.Write("<scr" & "ipt>" & vbCrLf
Response.Write("alert('" & sMessage & "');" & vbCrlf
Response.Write("</scr" & "ipt>" & vbCrLf


This will pop up a message on the client showing the text that's returned 
by the COM+ method.


Since ObjectControl_Activate and ObjectControl_Deactivate are Subs, they 
can't return a value. If you want to know whether they are called or not, 
you should either debug the DLL using Visual Basic (this can be quite 
troublesome) or use some logging functionality to write values to a text 
file.
A simple method that appends to a certain text file is all that's needed 
for this to work.


HtH


Imar



> Dear Sir/Madam

> Please give an answer to me about something of COM+.
I>  have an application on Visual Basic and base on COM technology. And 
now 
I>  want to convert my application to base on COM+. The following is what 
I 
h> ave done:
1>  - Add reference "COM+ Services Type Library" to the COM project.
2>  - In General Declarations code, I type:
	> Option Explicit
	> Implements ObjectControl
3>  - Implement following 3 Subs and Function:
	> Private Sub ObjectControl_Activate()
	>     Msgbox "Message of Start Activate"
	> End Sub

> 	Private Function ObjectControl_CanBePooled() As Boolean
	>     ObjectControl_CanBePooled = False
	> End Function

> 	Private Sub ObjectControl_Deactivate()
	>     Msgbox "Message of End Activate"
	> End Sub
	> 
	> Public Sub Show_msgbox()
	>     Msgbox "Message of Show_msgbox method"	
	> End Sub
4>  - I save this project with project name is Prj_com and class name is 
C> ls_com. After that I  make .dll file, everything is OK.
5>  - Use Components Sevices tools to install this COM.
6>  - Create an .ASP file with following code:
	> <%	
 >           Set myObj = Server.CreateObject("Prj_com .Cls_com")
	>    myObj.Show_msgbox	
	> %>
7>  - Create a Vitual directory on IIS Web server to run this .ASP file.
8>  - Run this .ASP file on web browser and I see the message of "Message 
of 
S> how_msgbox method" is appear.

> As me know, in this project I used ObjectContext, so when I call any 
m> ethod in this COM, then the message of "Message of Start Activate" 
will 
b> e call first, but I did not see that. Please give me a lead how to 
create 
t> he COM+ project.

> Best regards,

  Return to Index