proc IbServerEnvelopeOut

IbServerEnvelopeOut is a template for sending out responses as server messages that are properly formed SOAP envelopes. They are 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 IbClientEnvelopeOut,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. When you do this, difficulties could happen when namespaces and sophisticated features are involved.

######################################################################
# Name:                 ibServerEnvelopeOut
# 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
#                            send a web service reply.  This proc should only be used
#                            when IB is the server of a web service.  If IB is the
#                            web service client, then use the IBClientEnvelopeOut
#                            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 IbServerEnvelopeOut { 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
                    # get the soap envelope from the message
                    set cont [msgget $mh]
                    # create an empty ib Mime object
                    set ih1 [ibmimecreate]
                    # add ib Mime headers
                    ibmimeheaderadd $ih1 "IBStatus" "APP_RESP"
                    ibmimeheaderadd $ih1 "Content-Type" "multipart/mixed"
                    # 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"
                    # set the soap envelope as the part content
                    ibpartcontentset $ih1 $phl $cont
                    # update the message contents to the ibmime structure
                    msgset $mh [ibmimeencode $ih1]
                    lappend dispList "CONTINUE $mh"
         }

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

     return $dispList
}