Refresh Sample

A common annoyance that crops up while managing BizTalk Messaging is the complexity of refreshing a messaging object. For example, when an underlying envelope specification file is changed, the BizTalk Messaging envelope object must reset the document reference to effect the change in BizTalk Messaging. This sounds simple enough at first glance, but trying to change a document reference in an envelope associated with a port object proves impossible without first removing the reference. Now imagine changing the underlying document specification and refreshing the corresponding envelope where tens or hundreds of ports refer to it. This is an excellent opportunity to put the BizTalk Messaging Configuration object model to work.

Listing 19.34 contains VBScript code to refresh envelopes by first removing all port references, refreshing the envelope document, and finally reestablishing the envelope references. The code is fairly straightforward and dispenses with the usual UI niceties.

Note

The code in Listing 19.34 is also available for download at the Sams Publishing Web site.


Listing 19.34. Sample Code to Refresh an Envelope Messaging Object
On Error Resume Next : Err.Clear

' Create config objects
Set BT = CreateObject("BizTalk.BizTalkConfig")
Set env = BT.CreateEnvelope
Set port = BT.CreatePort

' Get Envelope name
env_name = InputBox("Enter the name of the envelope to refresh:")

' Try to load envelope
env.LoadByName env_name

If (Err.Num = 0) Then

    ' Find all ports that reference this envelope
    Set rs = BT.Ports

    Dim port_handles(0)

    Do While Not rs.EOF

        ' Load the port
        port.Load rs("id")

        ' Check if port references the envelope
        If port.Envelope = env.Handle Then
            ' Store the port handle
            size = UBound(port_handles)
            Redim Preserve port_handles(size + 1)
            port_handles(size) = port.Handle

            MsgBox "Storing " & port.Name & " reference to " & env.Name

            ' Clear the envelope reference
            port.Envelope = ""
            port.Save

        End If

        port.Clear

        rs.MoveNext

    Loop

    ' Refresh envelope specification
    ref = env.Reference
    env.Reference = ""
    env.Save
    env.Reference = ref

    ' Restore envelope references in ports
    For Each h In port_handles

        port.Load h

            MsgBox "Restoring reference to " & env.Name & " in " & port.Name

        port.Envelope = env.Handle
        port.Save
        port.Clear

    Next

    MsgBox "Envelope specification refreshed."

Else

    MsgBox "Unable to load specified envelope."

End If

The principles used in this sample can be applied to other messaging objects that need refreshing as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset