[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Wanted: Example of COM Server with Connection Points

Siegfried Heintze

9/28/2002 10:27:00 PM

Anyone have a chat program that uses DCOM remote activation to start up a
remote server where both client and server are written in C# or some other
.NET language?

I assume such a program would use connection points. I have not seen a
single example of .NET and connection points.

Thanks,
Siegfried


4 Answers

NETMaster

9/29/2002 12:30:00 PM

0

First, .NET/C# was NOT designed/optimized to build (D)COM servers (especially EXE servers).

If both sides are built with .NET, strictly use .NET Remoting!

Much better integrated then classic-DCOM is COM+ (Windows 2000+up) used with .NET
System.EnterpriseServices.ServicedComponent
namespace / classes.


Some hints/workarounds to use DCOM and .NET anyway:

SERVER SIDE:
You have to first build a .NET component like you would for
in-process COM activation and would be registered with the REGASM tool.
This supports connection-points, simply mapped to the well-known event/delegate model of .NET.
This is all well-documented in MSDN (keyword REGASM) or:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconmanagedunmanaged...
http://www.codeproject.com/dotnet/comi...

Now, to register .NET components for remote activation via DCOM, read:
....FrameworkSDK\Samples\Technologies\Interop\Advanced\comreg\readme.htm


CLIENT SIDE:
You can use C# code for DCOM activation like:

Type dcomType = Type.GetTypeFromProgID( "Company.Class", "REMOTE-PC-NAME", false );
Object dcomObj = Activator.CreateInstance( dcomType );

// casting to interface is like legacy QueryInterface :
IYourInterface iy = (IYourInterface) dcomObj;

// simple class casting :
YourClass yourInst = dcomObj as YourClass;

// you may need a wrapper for some tlb-imported types?
// YourClass yourWrapper = (YourClass) Marshal.CreateWrapperOfType( dcomObj, typeof(YourClass) );
...
// to release COM objects :
Marshal.ReleaseComObject( dcomObj );
dcomObj = null;

Note, there is no support for the security features of CoCreateInstanceEx.


AFAIK there is a limitation for TLB Type-Libraries built with TLBEXP,
you can't re-import them in .NET (using e.g. TLBIMP).

I guess it is possible to use all this 'workarounds',
but you must have good knowlegde of both, DCOM and .NET marshaling.




--
NETMaster (Thomas Scheidegger)
http://www.cetus-links.org/oo_c...


"Siegfried Heintze" <siegfried@heintze.com> wrote in message news:upc7mv18mf6p9d@corp.supernews.com...
> Anyone have a chat program that uses DCOM remote activation to start up a
> remote server where both client and server are written in C# or some other
> .NET language?
> I assume such a program would use connection points. I have not seen a
> single example of .NET and connection points.


(Li-Yan Zhang [MS])

9/30/2002 7:21:00 AM

0

Here is the .NET chat sample implemented with remoting techniques:
Remoting Example: Delegates and Events
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconremoting...
egatesevents.asp

Thanks,
Li-Yan Zhang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.got...

Siegfried Heintze

10/3/2002 4:25:00 AM

0

Is there support for CoInitializeSecurity?


NETMaster

10/3/2002 9:58:00 AM

0

So you can't use .NET Remoting? Sure?

> Is there support for CoInitializeSecurity?
No, you have to use PInvoke like:


// ======================== UNTESTED ================================
public enum RpcLevel // RPC_C_AUTHN_LEVEL_xxx
{
Default = 0,
None = 1,
Connect = 2,
Call = 3,
Pkt = 4,
PktIntegrity = 5,
PktPrivacy = 6
}

public enum RpcImpers // RPC_C_IMP_LEVEL_xxx
{
Default = 0,
Anonymous = 1,
Identify = 2,
Impersonate = 3,
Delegate = 4
}
...
[DllImport("ole32.dll") ]
public static extern int CoInitializeSecurity( IntPtr pVoid, int cAuthSvc,
IntPtr asAuthSvc, IntPtr pReserved1, RpcLevel level, RpcImpers impers,
IntPtr pAuthList, int dwCapabilities, IntPtr pReserved3 );

...

!!! Remove any [STAThread] / [MTAThread] attribute from main entry fn!
static void Main(...) {

System.Threading.Thread.CurrentThread.ApartmentState = ApartmentState.STA; // or MTA!

int hr = DCOM.CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero,
RpcLevel.Connect, RpcImpers.Impersonate,
IntPtr.Zero, 0, IntPtr.Zero );

// ========================================================


... and/or maybe DCOM App security configuration.

--
NETMaster (Thomas Scheidegger)
http://www.cetus-links.org/oo_c...