简体   繁体   中英

How to call a com+ component?

I'm making some archeology, dealing with COM+

I managed to enlist a simple COM dll as a COM+ component, so far so good.

So I've got this 'foobar' com+ component, with it's interface, and the method I'd like to call.

My question is then rally simple: how am I supposed to make a call to this component?

Any .NET or VB6 answer is accepted (I have to check the component is OK, don't care about the client)

Thanks

Edit (06/03/09): Well, I'm confused. so as to work properly, my COM+ component needs it's dll to be registered. Why not? But then, how to be sure I'm making a COM+ call, and not a COM one?

Simplest VB.NET code snippet possible:

Dim myCom As Object
myCom = CreateObject("MyCom.ProgId")
myCom.Method(parms)

You need to replace "MyCom.ProgId" with the actual ProgId of your component - you can get this from the General tab of the properties of the component in the Component Services admin tool (sounds like you've already got a grasp of that)

myCom.Method(parms)

is simply a place holder for whatever method you want to invoke, with the parameters that method takes.

Here's a link to some examples of the VB.NET syntax:

http://msdn.microsoft.com/library/de...eateObject.asp

http://www.samspublishing.com/articl...le.asp?p=25857

http://msdn.microsoft.com/library/en...asp?frame=true

Adam's code in VB6 is similar:

Dim myCom As Object
Set myCom = CreateObject("MyCom.ProgId")
myCom.Method(parms

This example is late bound and carries with it some performance penalty. You could call your method in an early bound manner, which avoids the penalty. In either VB6 or VB.NET, just add the COM+ dll to your references and you can call the object in this manner:

VB6

dim myCom as MyCom.ProgId
set myCom = new MyCom.ProgId
myCom.Method

VB.NET

dim myCom as new MyCom.ProgId
myCom.Method(...)

If all you are wanting is to check the component responds when called then use a quick VBScript rather than building something in VB6/VB.NET.

 Dim o : Set o = CreateObject("Lib.Class")
 o.YourMethod "someParam"

Watch your COM+ app in Component Services to see if the class requested spins up.

When you want to use COM+ for RMI then use this

Dim o As Object
Set o = CreateObject("Lib.Class", "MYSERVER")

where MYSERVER is the machine name where COM+ application is created and your DLL registered. Subsequently

o.YourMethod "someParam"

will be invoked remotely. If you are using only automation compatible interfaces, COM+ will successfully create a proxy for the RMI. Otherwise you'll need to provide the typelib on the client machine. This can be a separate TLB or the DLL itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM