Microsoft KB Archive/250292: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
(One intermediate revision by the same user not shown)
Line 67: Line 67:
     On Error GoTo CreateTransientSubscriptionError
     On Error GoTo CreateTransientSubscriptionError


     Set oCOMAdminCatalog = CreateObject("COMAdmin.COMAdminCatalog.1")
     Set oCOMAdminCatalog = CreateObject("COMAdmin.COMAdminCatalog.1")
     'Get the TRANSIENTSUBSCRIPTIONS collection
     'Get the TRANSIENTSUBSCRIPTIONS collection


     Set oTSCol = oCOMAdminCatalog.GetCollection("TransientSubscriptions")
     Set oTSCol = oCOMAdminCatalog.GetCollection("TransientSubscriptions")
     Set oSubscription = oTSCol.Add
     Set oSubscription = oTSCol.Add


          
          
     oSubscription.Value("SubscriberInterface") = objref
     oSubscription.Value("SubscriberInterface") = objref
     oSubscription.Value("EventCLSID") = clsid
     oSubscription.Value("EventCLSID") = clsid
     oSubscription.Value("Name") = "TransientSubscription"
     oSubscription.Value("Name") = "TransientSubscription"
      
      


Line 82: Line 82:
     oTSCol.SaveChanges
     oTSCol.SaveChanges


     CreateTransientSubscription = oSubscription.Value("ID")
     CreateTransientSubscription = oSubscription.Value("ID")


     Set oSubscription = Nothing
     Set oSubscription = Nothing
Line 93: Line 93:




     CreateTransientSubscription = ""
     CreateTransientSubscription = ""
     Err.Raise Err.Number, "[CreateTransientSubscription]" & Err.Source, Err.Description
     Err.Raise Err.Number, "[CreateTransientSubscription]" & Err.Source, Err.Description




Line 111: Line 111:
<pre class="codesample">    Dim oMyTicker As Object
<pre class="codesample">    Dim oMyTicker As Object
     Dim sSubscriptionID As String
     Dim sSubscriptionID As String
     Set oMyTicker = CreateObject(&quot;TheProject.CMyTicker&quot;)
     Set oMyTicker = CreateObject("TheProject.CMyTicker")
     sSubscriptionID = CreateTransientSubscription(&quot;{..CLSID for the Event Class..}&quot;, oMyTicker)
     sSubscriptionID = CreateTransientSubscription("{..CLSID for the Event Class..}", oMyTicker)
                     </pre></li></ol>
                     </pre></li></ol>



Latest revision as of 13:51, 21 July 2020

Knowledge Base


How To Create a COM+ Event Transient Subscription in Visual Basic

Article ID: 250292

Article Last Modified on 7/22/2005



APPLIES TO

  • Microsoft COM+ 1.0



This article was previously published under Q250292

SUMMARY

This article explains how to use Microsoft Visual Basic to add a transient subscription to a COM+ Event class.

MORE INFORMATION

The COM+ Events service allows you to configure an Event Class that when called, rather than executing its methods, broadcasts the call to one or more subscribers that contains the implementation to be executed. There are two main types of subscribers: persistent and transient. Persistent subscriptions are configured through the Component Services snap-in or through the COM+ Admin objects, and the information is stored on disk. Transient subscriptions have to be added in a run-time file and are lost in case of a system failure, but they allow for added flexibility of subscriber lifetime and implementation strategy.

Following are the two steps required to add a transient subscription:

  1. Create a COM+ server (an .exe, a .dll or an .ocx file) with an object that implements the interfaces or methods you want to subscribe to.
  2. When you want to create your transient subscription, call the following code passing in the CLSID of the Event class and a reference to the subscriber you created in the previous step.

    Public Function CreateTransientSubscription(ByVal clsid As String, ByVal objref As Object) As String
    
        Dim oCOMAdminCatalog As COMAdmin.COMAdminCatalog
        Dim oTSCol As COMAdminCatalogCollection
        Dim oSubscription As ICatalogObject
        
        On Error GoTo CreateTransientSubscriptionError
    
        Set oCOMAdminCatalog = CreateObject("COMAdmin.COMAdminCatalog.1")
        'Get the TRANSIENTSUBSCRIPTIONS collection
    
        Set oTSCol = oCOMAdminCatalog.GetCollection("TransientSubscriptions")
        Set oSubscription = oTSCol.Add
    
            
        oSubscription.Value("SubscriberInterface") = objref
        oSubscription.Value("EventCLSID") = clsid
        oSubscription.Value("Name") = "TransientSubscription"
        
    
    
        oTSCol.SaveChanges
    
        CreateTransientSubscription = oSubscription.Value("ID")
    
        Set oSubscription = Nothing
        Set oTSCol = Nothing
        Set oCOMAdminCatalog = Nothing
        
    Exit Function
    
    CreateTransientSubscriptionError:
    
    
         CreateTransientSubscription = ""
         Err.Raise Err.Number, "[CreateTransientSubscription]" & Err.Source, Err.Description
    
    
    End Function
                            


    This code returns a string which is a GUID and that can be used as a handle or cookie to revoke the subscription later. (To remove the subscription just call Remove on the TransientSubscriptions collection passing in the index corresponding to the subscription with the GUID you received as a cookie).

A sample for calling this function is as follows:

  1. Create an Event class that supports the interface IStockTicker, which has one method, UpdateStock.
  2. In your subscriber project, add a class that implements the IStockTicker interface.
  3. When you want to subscribe execute the following code:

        Dim oMyTicker As Object
        Dim sSubscriptionID As String
        Set oMyTicker = CreateObject("TheProject.CMyTicker")
        sSubscriptionID = CreateTransientSubscription("{..CLSID for the Event Class..}", oMyTicker)
                        

You can get the Event class CLSID from the Component Services MMC snap-in, in the General tab for the Event Class.

REFERENCES

For a Microsoft Visual Basic .NET version of this article, see 312902.

Please read the MSDN Documentation on COM+ Events for more information.



Additional query words: COM+ Event subscription transient TRANSIENTSUBSCRIPTIONS

Keywords: kbhowto kbcompluslce kbsysadmin kbcompluscatalog KB250292