"Slavan" <vy*****************@gmail.comwrote in message
news:11**********************@y5g2000hsa.googlegro ups.com...
On Apr 30, 4:10 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
>"Nicholas Paldino [.NET/C# MVP]" <m...@spam.guard.caspershouse.comwrote
in
messagenews:eV**************@TK2MSFTNGP03.phx.gbl ...
Slavan,
Is SomeType.SomeClass a .NET component? If so, you need to have a
reference to the original assembly and create the type using the new
keyword. .NET components hosted in COM+ can not be created in .NET
through COM interop (which is essentially what you are trying to do, if
this is the case).
Hope this helps.
No, this is not true.
You can register a .NET component in the COM+ catalog and call it from
managed code as well as from native COM code.
What the OP it trying to do is create an instance of a .NET class using
late
binding, no COM interop is involved here. When creating an instance from
native COM clients, then you effective create this instance through COM
interop.
Willy.
Willy.
Could you provide code example on how to call COM+ component from .NET
client?
It depends on how you would like to call the component, you can use early
binding as well as late binding.
Using late binding , you need to use reflection like this:
// say you have a method like....
public void SomeMethod(string message)
....
then your client can call it like this...
....
t = Type.GetTypeFromProgID("SomeType.SomeClass", true);
helper = Activator.CreateInstance(t);
// here I call "SomeMethod" passing a string as argument using
reflection.
helper.GetType().InvokeMember("SomeMethod", BindingFlags.Default
| BindingFlags.InvokeMethod, null, helper, new object[] {"Test" });
...
However, it's much better to call it using early binding,
1. Using a common interface assembly
// Interface - common assembly.
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("....................................")]
public interface ISample
{
void SomeMethod(string message);
}
// Sample implementation class (another assembly)
// Class implementing ISample
public class Sample : ServicedComponent, ISample
{
public void SomeMethod(string xx)
{..}
}
Your client simply has to set a reference to the "common Interface"
assembly...
and call the method like this.
ISample sample;
// create instance..
Type t = Type.GetTypeFromProgID("SomeType.SomeClass", true);
object helper = Activator.CreateInstance(t);
sample = helper as ISample;
// Call method
sample.SomeMethod("test");
2. Using a reference to the server library.
Here you can just create an instance of the class using new.
Sample sample = new Sample();
sample.SomeMethod(...).
Willy.