tags:

views:

547

answers:

4

Hi,

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?

+2  A: 

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
your links seems dead, but thanks anyway for your insight. All I lack now is the way to make a reference to the COM+ component, so as to be able to compile my client
Vinzz
You don't need a reference to your COM component when you late binding - which is the syntax in my code example. The runtime will lookup the component by the ProgId string, load into memory, and try to invoke the method in your code.This can create some new runtime error that you havent seen before if you try to invoke a method that doesnt exist, or pass bad parameters. Early binding prevents these types of errors, b/c the compiler will catch them.
Adam
+1  A: 

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(...)
AngryHacker
Thanks, but I've got to make some kind of reference so as to compile this project, right? How can I make a reference to the COM+ component?
Vinzz
COM+ component is the same as a COM component, just with extra transactional goo, thus you reference it the same way. In VB6, go to Project/References menu. In VB.NET, right-click on a project in the Solution Explorer and pick Add References...
AngryHacker
+1  A: 

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.

AnthonyWJones
Thanks a lot, it worked perfectly
Vinzz
Err... in fact, no, my vanilla COM dll was registered, and it answered my call, not the COM+ component
Vinzz
You should drag the dll into a COM+ app in Component Services after the COM component has been registered. COM+ will then fix up the registry entries to direct the CreateObject call. You are using a server app not a library app right?
AnthonyWJones
+1  A: 

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.

wqw