proc IbClientEnvelopeOut

IbClientEnvelopeOut is a template for sending out requests as client messages that are properly formed SOAP envelopes. This is used within the sample sites that take advantage of the XML capabilities (XML formats) and translations, with the help of the XSD/WSDL tools.

This proc, along with IbEnvelopIn and IbServerEnvelopeOut,as a group are considered a better approach to the SOAP/XML messaging solution than the IbOutXML/IbInXML pair. This is because of better overall XML handling.

The hard-coded string and regular expression techniques that are used in that pair can be used with XML. If this is used, then difficulties could happen when namespaces and sophisticated features are involved.

######################################################################
#Name:                 IbClientEnvelopeOut
# Purpose:              The message coming into this proc should contain an
#                           XML soap envelope string.  The proc wraps this in an
#                           ibmime structure to send to IB, which IB will use to
#                           invoke a web service.  This proc should only be used
#                           when IB is the client to a web service.  If IB is the
#                           web service server, then use the IBServerEnvelopeOut
#                           proc.
#UPoC type:           tps
#Args:                   tps keyedlist containing these keys:
#                           MODE     run mode ("start", "run" or "time")
#                           MSGID    message handle
#                           ARGS      user-supplied arguments:
#                                            <describe user-supplied args here>
#
#Returns:            tps disposition list:
#                           <describe dispositions used here>
#

proc IbClientEnvelopeOut { args } {
     keylget args MODE mode              ;# Fetch mode

     set dispList {}                                                ;# Nothing to return

     switch -exact -- $mode {
          start {
               # Perform special init functions
                    # N.B.: there may or may not be a MSGID key in args
               package require ibmime
          }

          run {
                     # 'run' mode always has a MSGID; fetch and process it
                     global env
                     keylget args MSGID mh
                     set cont [msgget $mh]
                     # create an empty ib Mime object
                     set ih1 [ibmimecreate]
                     # add ib Mime headers
                     ibmimeheaderadd $ih1 "IBSite" $env(HCISITE)
                     ibmimeheaderadd $ih1 "IBThread" [msgmetaget $mh DESTCONN]
                     # create the 1st part of this ib Mime
                     set phl [ibpartcreate $ih1]
                     # add headers of the 1st part
                     ibpartheaderadd $ih1 $phl "Content-Type" "text/xml"
                     # add original message content as the 1st part. 
                     ibpartcontentset $ih1 $phl $cont
                     msgset $mh [ibmimeencode $ih1]
                     lappend dispList "CONTINUE $mh"
          }

          time {   # Timer-based processing        }
        
          shutdown {
                    # Doing some clean-up work 
                   }
     }

     return $dispList
}