Procedure for Calling C++ Decode Methods

NOTE: As of version 1.1, C++ exceptions are no longer used. Therefore, any application programs that used only try/catch blocks to detect errors will not work properly. The return status code from the decode method is the only mechanism used to report error conditions.

The procedure to invoke a C++ decode method is as follows:

  1. Create an instance of the generated type class into which the XML message data is to be decoded.

  2. Create an instance of an input stream or message buffer object from which the XML message to be decoded will be read.

  3. Create an instance of the generated global element control class to link the generated type class instance with the message buffer or input stream instance.

  4. Invoke the control class decode method.

  5. If decoding was successful (indicated by return status equal to zero), the decoded data will now be available for use in the generated type variable. The generated print method can be called at this time to examine the contents of the data structure.

  6. If decoding failed, the message buffer or stream printErrorInfo method can be invoked to print the reason for failure.

A program fragment that could be used to decode an employee record is as follows:

   #include "employee.h"
   #include "rtxmlsrc/rtXmlCppMsgBuf.h"

   int main (int argc, char** argv)
   {
      int i, stat;
      const char* filename = "message.xml";
      OSBOOL trace = TRUE, verbose = FALSE;

      // Step 1: create instance of class into which message will be decoded

      PersonnelRecord value;

      // Step 2: create an input stream from which the message will be read

      OSFileInputStream in (filename);
      OSXMLDecodeBuffer decodeBuffer (in);

      // Step 3: create a control class instance to tie the data object
      // and input stream object together.

      personnelRecord_CC personnelRecord (decodeBuffer, value);

      if (verbose)
         rtxSetDiag (personnelRecord.getCtxtPtr(), 1);

      // Step 4: Decode
  
      stat = personnelRecord.decode();

      if (0 == stat) {
         if (trace) {
            printf ("decoded XML message:\n");
            personnelRecord.print ("personnelRecord");
            printf ("\n");
         }
      }
      else {
         printf ("Decoding failed\n");
         decodeBuffer.printErrorInfo();
      }

      return stat;
   }

The calling procedure on WSDL input operation decode method is the same as that on XSD glabal element deocde method. When calling a C++ XML decode method for WSDL operation output, the user must initialize a fault variable. This is a variable of type Oper_Fault, where Oper is the operation name.

The following code snippet could be used to decode an Add operation output for example CalcWSDL:

     Add_Output value;
     Add_Fault fault;
     ...
     Add_Output_CC pdu (decodeBuffer, value, fault);
     decodeBuffer.setDiag (verbose);

     // Decode
     in.reset ();
     decodeBuffer.resetErrorInfo ();
     stat = pdu.decodeFrom(decodeBuffer);

     if (0 == stat) {
        if (trace) {
           printf ("decoded XML message:\n");
           pdu.print ("Add_Output");
           printf ("\n");
        }
     }
     else if (RTERR_SOAPFAULT == stat) {
        if (trace) {
           printf ("decoded XML message:\n");
           fault.print ("Add_Fault");
           printf ("\n");
        }
     }
     else {
        printf ("Decoding failed\n");
        decodeBuffer.printErrorInfo();
        return stat;
     }