Thank you Slava,
The solution is a very simple test for transient subscriptions.
I Have a project "EventClass". This is the code:
Imports System.EnterpriseServices
Imports System.Runtime.InteropServices
<Guid("57CD98DE-81A5-4a0e-AED9-972428DA26EF")> _
Public Interface IEventosPedidos
Sub PedidoRealizado(ByVal IdPedido As Integer)
End Interface
<Guid("DE1D42F4-3538-4d9d-B587-1B5F014D834F"), _
EventClass(FireInParallel:=True), _
JustInTimeActivation(True), _
ObjectPooling(True)> _
Public Class EventosPedidos
Inherits ServicedComponent
Implements IEventosPedidos
Public Sub PedidoRealizado(ByVal IdPedido As Integer) Implements
IEventosPedidos.PedidoRealizado
Throw New NotImplementedException("Esta clase debe llamarse por
medio de eventos COM+")
End Sub
End Class
And here is the AssemblyInfo.vb:
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyKeyFile("c:\eidos.snk")>
<Assembly: ApplicationName("EventosPedidos")>
<Assembly: ApplicationActivation(ActivationOption.Server)>
<Assembly: ApplicationAccessControl(False)>
I have generated this project, put the assembly into the GAC and registered
it into COM+ using RegSvcs.exe
I also have a project "Subscriptor". And here is the code:
Imports System.EnterpriseServices
Public Class Subcriptor
Inherits ServicedComponent
Implements EventClass.IEventosPedidos
Public Sub PedidoRealizado(ByVal IdPedido As Integer) Implements
EventClass.IEventosPedidos.PedidoRealizado
Debug.WriteLine("Pedido n?" & IdPedido & " realizado")
End Sub
End Class
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyKeyFile("c:\eidos.snk")>
<Assembly: ApplicationName("Subscriptor")>
<Assembly: ApplicationActivation(ActivationOption.Library)>
<Assembly: ApplicationAccessControl(False)>
And a Windows project, the client:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim s As Object = New Subscriptor.Subcriptor
Dim st As New SubscripcionesTransitorias.SubscripcionesTransitorias
Dim Id As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
p.RealizarPedido(1)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Id = st.A?adir(s)
End Sub
End Class
the exception is raised when calling st.A?adir(s).
SubscripcionesTransitorias is implemented in a separate dll:
Public Class SubscripcionesTransitorias
Public Function A?adir(ByVal Objeto As Object) As String
Dim cat As Object = CreateObject("COMAdmin.COMAdminCatalog")
Dim Subscripciones As Object =
cat.GetCollection("TransientSubscriptions")
Dim Subscripci?n As Object = Subscripciones.Add()
If Subscripci?n Is Nothing Then
Throw New Exception("No se pueden a?adir subscripciones
transitorias")
End If
Subscripci?n.Value("Name") = "TransientSubscription"
Subscripci?n.Value("EventCLSID") =
"{DE1D42F4-3538-4D9D-B587-1B5F014D834F}"
' COMException "member not found." What member is not found ????
Subscripci?n.Value("SubscriberInterface") = Objeto
Subscripciones.SaveChanges()
A?adir = Subscripci?n.Key
Marshal.ReleaseComObject(Subscripci?n)
Marshal.ReleaseComObject(Subscripciones)
Marshal.ReleaseComObject(cat)
End Function
Public Sub Quitar(ByVal Id As String)
Dim cat As Object = CreateObject("COMAdmin.COMAdminCatalog")
Dim Subscripciones As Object =
cat.GetCollection("TransientSubscriptions")
Subscripciones.PopulateByKey(New String() {Id})
If Subscripciones.Count = 1 Then
Subscripciones.Remove(0)
Subscripciones.SaveChanges()
End If
Marshal.ReleaseComObject(Subscripciones)
Marshal.ReleaseComObject(cat)
End Sub
End Class
I'm using Windows XP Service Pack 1a, Visual Studio 2003, and .NET Framework
1.1
Regards,
Jes?s L?pez
Slava Gurevich - 15 Dec 2003 13:06 GMT
Hi,
try the following:
Subscription.Value("SubscriberInterface") =
Marshal.GetIUnknownForObject(Objeto)
Regards,
Slava Gurevich
>Thank you Slava,
>
[quoted text clipped - 129 lines]
>
>Jesús López
Slava Gurevich - 15 Dec 2003 14:57 GMT
Actually this would be even better for avoiding a refcount leak:
Dim pUnk As IntPtr = Marshal.GetIUnknownForObject(Objeto)
Subscription.Value("SubscriberInterface") = pUnk
Marshal.Release(pUnk)
Slava Gurevich
>Hi,
>try the following:
[quoted text clipped - 5 lines]
>
>Slava Gurevich
SqlRanger - 15 Dec 2003 15:27 GMT
Thank you again Slava.

Signature
Regards
Jesús López
SqlRanger - 15 Dec 2003 15:00 GMT
Thank you very very much Slava. That worked fine !!!

Signature
Regards,
Jesús López