Archive for the ‘COM’ Category

Using COM+ Services in .NET

Full Source Code: here (VS 2010, VB, .Net 4.0)

Mainly based on: Using COM+ Services in .NET by Tim McCarthy, InterKnowlogy // Paul D. Sheriff, PDSA, Inc.

Summary: Add new Microsoft .NET components to existing COM and COM+ applications and they will be able to work together; this will help you if you need to develop a .NET application that can do things like participate in transactions, take advantage of role-based security, or interact with a queue. (14 printed pages)

Class Library source code (VB):

Imports System.EnterpriseServices
Imports System.Reflection
Imports System.Runtime.InteropServices

'COM+ Registration details

'Supply the COM+ application name
<Assembly: ApplicationNameAttribute("ComPlusExample")>

'Supply a strong-name assembly
<Assembly: _

'Role-based security attribute
<Assembly: SecurityRoleAttribute("Managers", False)>

<Assembly: ApplicationAccessControlAttribute(AccessChecksLevel:=AccessChecksLevelOption.ApplicationComponent)>

<Assembly: ApplicationActivationAttribute(ActivationOption.Server)>

<Assembly: ApplicationQueuingAttribute(Enabled:=True,QueueListenerEnabled:=True)>

<TransactionAttribute(TransactionOption.Required)> _
Public Class COMPlusServices
Inherits ServicedComponent

Public Sub New()
End Sub

<AutoComplete()> Public Function DoTransaction() _
As String
Return "Success with COM+, Nathan"
End Function

Public Function IsManager() As Boolean

Dim objCallContext As SecurityCallContext = SecurityCallContext.CurrentCall
IsManager = objCallContext.IsCallerInRole("Managers")

End Function

Public Function EsPruebaComPlus() As Boolean

Dim objCallContext As SecurityCallContext = SecurityCallContext.CurrentCall
EsPruebaComPlus = objCallContext.IsCallerInRole("PruebaComPlus")

End Function

Public Sub QueueTest()
System.Diagnostics.EventLog.WriteEntry("COMPlusServces", "Queue Test", Diagnostics.EventLogEntryType.Error)
End Sub

End Class

Console Client source code (VB)

Imports COMPlusServicesVB

Module modMain
Sub Main()

Dim objCOMPlus As New COMPlusServicesVB.COMPlusServices()
Console.WriteLine("DoTransacction :" & objCOMPlus.DoTransaction)
Console.WriteLine("IsManager: " & objCOMPlus.IsManager().ToString)
Console.WriteLine("EsPruebaComPlus: " & objCOMPlus.EsPruebaComPlus().ToString)
Catch ex As Exception
Console.WriteLine("An error occurred. " & "Details:  " & ex.Message)
End Try

End Sub

Sub Cola()
Dim objTest As New COMPlusServicesVB.COMPlusServices()
Dim strMoniker As String
strMoniker = "queue:/new:COMPlusServicesVB.COMPlusServices"
objTest = GetObject(strMoniker)

End Sub
End Module

More references:

Transacciones Automáticas: Cómo usar transacciones a través de los Enterprise Services (COM+)

Transacciones en Biztalk con .NET y COM+ (Terminado)

Parte I Introducción: Descripción del escenario, datos del ambiente y lo que deben saber sobre transacciones

Parte II .NET y COM+: Preparando nuestro componente transaccional y comprobando su funcionamiento

Parte III BTS, .NET y COM+: Realizando transacciones en una orquestación con el componente construido

Calling Managed .NET C# COM Objects from Unmanaged C++ Code

Found this excellent, basic, step by step post about IPC (Inter-Process Communication) between Managed .Net  C# COM objects and Unmanaged C++ code

Calling Managed .NET C# COM Objects from Unmanaged C++ Code