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: _
AssemblyKeyFileAttribute("bin/ComPlusExample.snk")>

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

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

<Assembly: ApplicationActivationAttribute(ActivationOption.Server)>

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

'********************************************
<ComVisible(True)>
<TransactionAttribute(TransactionOption.Required)> _
Public Class COMPlusServices
Inherits ServicedComponent

Public Sub New()
MyBase.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()

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

End Sub

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

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

One response to this post.

  1. This design is wicked! You definitely know how
    to keep a reader entertained. Between your wit and your
    videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job.

    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

    Responder

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: