Dealing with .NET Enterprise Services: .NET Remoting, Web Services and Service Components - Working with a basic COM application
(Page 3 of 6 )
I already introduced COM+ issues in my earlier article. So, at the moment, I don’t want to go into its details. Let us directly attack the code.
Imports System.EnterpriseServices
Imports System.Reflection
'c:...bin/> sn -k COMPlusEx1Srv.snk
'regsvcs [/reconfig] /fc COMPlusEx1Srv.snk
<Assembly: ApplicationName("COMPlusEx1Srv")>
<Assembly: AssemblyKeyFile("../../bin/COMPlusEx1Srv.snk")>
<Assembly: ApplicationAccessControl()>
Public Class Test
Inherits ServicedComponent
Public Function getSum(ByVal a As Integer, ByVal b As
Integer) As Integer
Return (a + b)
End Function
Public Function getProduct(ByVal a As Integer, ByVal b As
Integer) As Integer
Return (a * b)
End Function
End Class
Any COM+ application should be extended from the base class “ServicedComponent.” And we also need to import “System.EnterpriseServices” and “System.Reflection.” The most important issue to remember is that the COM+ application needs to be strongly signed. In the above program, two lines of comments exist to assist you in creating the “strong name key pair” and registering our application with COM+ services.
The two methods I defined in the above program are only for demonstration and not practical.
It is quite simple to create an object based on a COM+ definition. The following code shows you how you can access the above COM+ application.
Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCal.Click
Dim obj As New COMPlusEx1Srv.Test
MessageBox.Show(obj.getSum(CInt(Me.txtFirst.Text), CInt
(Me.txtSecond.Text)))
MessageBox.Show(obj.getProduct(CInt(Me.txtFirst.Text),
CInt(Me.txtSecond.Text)))
End Sub
It is as simple as creating your own object and accessing its members.
Next: Working with a database-based COM application >>
More .NET Articles
More By Jagadish Chaterjee