Figure 4   Attend.idl


 interface IAttend : IDispatch
     {
         import "oaidl.idl";
         HRESULT Post(        
             [in] long lNumAtt,
             [in] BSTR bstrRegLastName,
             [in] BSTR bstrAreaOfInterest);
             [out, retval] VARIANT* pvRetVal);
     };
 . . .
     interface IContact : IDispatch
     {
         import "oaidl.idl";
 
         HRESULT Add(        
             [in] BSTR bstrLastName,
             [in] BSTR bstrFirstName,
             [in] BSTR bstrOfficePhone,
             [in] BSTR bstrFax,
             [in] BSTR bstrCompany,
             [in] BSTR bstrTitle);
             [out, retval] VARIANT* pvRetVal);
     };
 . . .
     [
         uuid(7397C3F3-0768-11d1-B461-00A0C9165BE7),
         helpstring("Seminar Reservation Attendee Class"),
         JAVACLASS("Attend.AttendObj"),
         PROGID("Reservation.Seminar"),
         TRANSACTION_REQUIRED
     ]
     coclass CAttend
     {
         [default] interface IAttend;
     };
 
     [
         uuid(7397C3F4-0768-11d1-B461-00A0C9165BE7),
         helpstring("Contact Information Class"),
         JAVACLASS("Attend.ContactObj"),
         PROGID("Reservation.Contact"),
         TRANSACTION_REQUIRED
     ]
     coclass CContact
     {
         [default] interface IContact;
     };


Figure 7   Contact.asp


 <%@ TRANSACTION=REQUIRED LANGUAGE="VBSCRIPT" %>
 <% Response.Buffer = true %>
 
 <%
 Set Attend = Server.CreateObject("Reservation.Seminar")
 Set Contact = Server.CreateObject("Reservation.Contact")
 
 If Attend Is Nothing Then
     Response.Write("Error: Reservation.Seminar Object Creation Failed")
 Else
     On Error Resume Next
     Ret = CInt(Attend.Post(CInt(Request.Form("NumAttendConf")), _
           CStr(Request.Form("lastname")),CStr(Request.Form("InterestAreaConf"))))
     If Ret <> 0 Then
         Response.Write "<p><b>Error: Registration Post </b>."
     End If
     If Err.Number <> 0 Then
         GetObjectContext.SetAbort
     End If 
 End If    
 
 If Contact Is Nothing Then
     Response.Write("Error: Reservation.Contact Object Creation Failed")
 Else
     Ret = CInt(Contact.Add(CStr(Request.Form("lastname")), _
           CStr(Request.Form("firstname")), CStr(Request.Form("officephone")), _
           CStr(Request.Form("officefax")), CStr(Request.Form("company")), _
           CStr(Request.Form("Title"))))
     If Ret <> 0 Then
         Response.Write "<p><b>Error: Error Adding Contact to database </b>."
     End If
     If Err.Number <> 0 Then
         GetObjectContext.SetAbort
     End If 
 End If
 
 'Destroy the component when your done
 Set Attend = Nothing
 Set Contact = Nothing    
 
     ' The Transacted Script Commit Handler.  This sub-routine
     ' will be called if the transacted script commits.
     
     Sub OnTransactionCommit()
         Response.Write "<p><b>You have successfully registered and your contact 
                        information has been added to our database</b>." 
     end sub
 
     ' The Transacted Script Abort Handler.  This sub-routine
     ' will be called if the script transacted aborts
     
     Sub OnTransactionAbort()
         Response.Write "<p><b>An error occured: please try again</b>."%>
         <hr>
         <p><a href="Register.asp">Try Again?</a> </p>
         <%
     end sub
 
 Response.end %>
 
 <HTML>
 <HEAD>
 <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
 <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
 <TITLE>Contact Confirmation Status</TITLE>
 </HEAD>
 <BODY>
 
 <p align="center"><font color="#000000" face="Tahoma"><img src=
 "file:///D:/Christian/Corporate/Nanonew.gif" width="224" height="72"></font></p>
 
 <p align="center"><font color="#000000" size="6" face="Tahoma"><strong>NanoSoft
 Developers Conference (NDC)</strong></font></p>
 
 <hr>
 
 <p align="center"><font color="#000000" size="5" face="Tahoma">Contact
 Confirmation</font></p>
 
 <p>&nbsp;</p>
 
 <hr>
 <p><a href="Register.asp">Go Back to the registration page.</a> </p>
 
 </BODY>
 </HTML>


Figure 8   Confirm.asp


 <%LANGUAGE="VBScript" %>
 <%
 Function RadioButtonHTML(Name, Text, Value)
     HTML = "<input type=radio name=InterestAreaConf value=" + Name
     If (Name = Value) THEN
         HTML = HTML + " checked "
     End If
 
     HTML = HTML + ">" + Text
     RadioButtonHTML = HTML
 End Function %>
 
 <html>
 <head>
 <meta name="GENERATOR" content="Microsoft Visual InterDev 1.0">
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 <title>Confirmation Screen</title>
 </head>
 <body>
 
 <p align="center"><font color="#000000" face="Tahoma"><img src=
   "file:///D:/Christian/Corporate/Nanonew.gif" width="224" height="72"></font></p>
 
 <p align="center"><font color="#000000" size="6" face="Tahoma"><strong>NanoSoft
   Developers Conference (NDC)</strong></font></p>
 
 <hr>
 
 <p align="center"><font color="#000000" size="5" face="Tahoma">On-Line
   Confirmation</font></p>
 
 <p>&nbsp;</p>
 
 <%If Request.Form("Confirmation") = "ON" Then %>
     <p>Please provide the following information so we can fax the confirmation to you:</p>
     
     <form method="POST" action="contact.asp">
     <p>Number Attending Conference (Confirm): <input type="text" size="2"
     maxlength="2" name="NumAttendConf" value="<%=Request.Form("NumAttend")%>"></p>
     <p>Area of Interest (Confirm): </p>
     <p><%Response.Write(RadioButtonHTML("VisualB", "Visual Basic",
                         Request.Form("InterestArea")))
          Response.Write(RadioButtonHTML("VisualI", "Visual InterDev",
                         Request.Form("InterestArea")))
          Response.Write(RadioButtonHTML("VisualC", "Visual C++",
                         Request.Form("InterestArea")))
          Response.Write(RadioButtonHTML("VisualJ", "Visual J++",
                         Request.Form("InterestArea")))%>
     </p>    
     <p>First Name: <input type="text" size="20" name="firstname"> </p>
     <p>Last Name: <input type="text" size="20" name="lastname"
                    value="<%=Request.Form("RegLastName")%>"></p>
     <p>Office Phone: <input type="text" size="10" name="officephone"> </p>
     <p>Office Fax: <input type="text" size="10" name="officefax"></p>
     <p>Company: <input type="text" size="40" name="company"></p>
     <p>Title: <input type="text" size="40" name="title"></p>
     <p><input type="submit" name="submit" value="Submit"> <input type="reset"
         name="reset" value=" Clear  "></p>
     </form>
 <%Else
     Set Attend = Server.CreateObject("Reservation.Seminar")
     Ret = CInt(Attend.Post(CInt(Request.Form("NumAttend")),
           CStr(Request.Form("RegLastName")), CStr(Request.Form("InterestArea"))))
     If Ret <> 0 Then
         Response.Write "<p><b>Registration Post Error </b>."
     Else
         Response.Write "<p><b>You've been successfully registered to the conference!
                        </b>."
     End If 
     
     Set Attend = Nothing
 End If
 %>
 
 <hr>
 
 <p><a href="Register.asp">Go to the Registration Page</a> </p>
 
 </body>
 </html>


Figure 9   registration.asp


 <%@ LANGUAGE="VBSCRIPT" %>
 
 <html>
 <head>
 <meta name="GENERATOR" content="Microsoft Visual InterDev 1.0">
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 <title>Main Registration Form - NanoSoft Conference</title>
 </head>
 <body>
 <p align="center"><font color="#000000" face="Tahoma"><img src=
 "file:///D:/Christian/Corporate/Nanonew.gif" width="224" height="72"></font></p>
 <p align="center"><font color="#000000" size="6" face="Tahoma"><strong>NanoSoft
 Developers Conference (NDC)</strong></font></p>
 <hr>
 <p align="center"><font color="#000000" size="5" face="Tahoma">On-Line
 Registration</font></p>
 
 <p>&nbsp;</p>
 
 <p>Please provide the following information so that we can better
 estimate the number of attendees:</p>
 <form method="POST" action="Confirm.asp" name="FrontPage_Form1">
 <p>Number Attending Conference: <input type="text" size="2" maxlength="2"
    name="NumAttend"></p>
     <p>Area of Interest: </p>
     <p>
     <input type="radio" name="InterestArea" value="VisualB">VisualBasic
     <input type="radio" name="InterestArea" value="VisualI">Visual InterDev 
     <input type="radio" name="InterestArea" value="VisualC">Visual C++ 
     <input type="radio" checked name="InterestArea" value="VisualJ">Visual J++</p>
     <p>Lastname (Registered As): <input type="text" size="20" name="RegLastName"> </p>
     <p>Fax Confirmation: <input type="checkbox" checked name="Confirmation"
                           value="ON"></p>
     <p><input type="submit" name="submit" value="Submit"> <input type="reset"
         name="Reset" value="Clear"></p>
 </form>
 <p>&nbsp;</p>
 </body>
 </html>


Figure 10   Attend.ContactObj.Add


 public Variant Add (String strLastName, String strFirstName, 
 String strOfficePhone, String strFax, String strCompany, String strTitle)
 {
     IAttend        Attend = null;
     int            nRows, nRet = -1;
     boolean        bSuccess = false;
                 
     try
     {
         Attend = (IAttend)MTx.GetObjectContext().CreateInstance(
                   CAttend.clsid, IAttend.iid);
 
         // Call post to register the new contact, assume he likes VJ++
         Attend.Post(1, strLastName, "VisualJ");


Figure 11   Attend.ContactObj.java


 ////////////////////////////////////////////////////////////////////////////////
 //           Seminar (Conference) Registration Web Application using MTS 2.0 and 
 //           Java and Active Server Pages 2.0
 //
 //           1996 Microsoft Interactive Developer Magazine
 ////////////////////////////////////////////////////////////////////////////////
 
 package Attend;
 
 import java.applet.*;
 import com.ms.mtx.*;
 import msado15.*;
 import com.ms.com.*;
 
 public class AttendObj implements IAttend
 {
     
     // ADO Data members
     private    Connection  m_c     = new Connection();
     private    _Connection m_ic    = (_Connection) m_c;
     private Errors m_Errs          = null;
     private msado15.Error m_Err    = null;
 
     // main() used for DEBUGGING ONLY!!!
     // use this for debugging as standalone
     public static void main (String[] args)
     {
         AttendObj    a = new AttendObj();
         int            nNumAttend = 1;
         Variant        vResult = new Variant();
         Variant        vRet = new Variant();
         
         // FOR DEBUGGING PURPOSES ONLY: NO HTML file is supplied so use the JView 
         // stand-alone interpreter 
         try
         {
 
             // REMEMBER if this function is called from an generic applet 
             // comment out the MTx lines near the end of the "Post" function
             // otherwise a NullPoinerException will be thrown
             vRet = a.Post (nNumAttend, "TestName-Jones6", "VisualJ");
         }
         catch (Throwable t)
         {
             t.printStackTrace();
         }
 
         try 
         {
             System.in.read(); 
         }
         catch (Exception e)
         {;}
     }
     
     //----------------------------------------------------------------------------
     // Post: Adds the registration information to the SemResDB database including
     //       the number attending the seminar, the registered name, and the 
     //       specific area of interest.
     //       ADO - Active Data Objects was used as the database transport method.
     //----------------------------------------------------------------------------
     public Variant Post(int nNumAtt, String strRegName, String strAreaOfInterest)
     throws ComFailException
     {
         boolean           bSuccess = false;
         String            strSQL = "";    
         String            strConnect = "DSN=SemResDB;UID=sa;PWD=";
         int               nRecordCount;
         Variant           vConnection = new Variant();
         Variant           vRowsAffected = new Variant();
         
         // First of all, get the object context
         IObjectContext ctxObject = MTx.GetObjectContext();
 
         try
         {
             // Check for security
             if (!ctxObject.IsCallerInRole ("Attendee"))
                 throw new ComFailException ("Need 'Attendees' role to register for 
                                             this conference");
 
             // Setup the SQL Statement for record insertion
             // This is the SQL call used to insert my new record into the 
             // Registration database using ADO
             strSQL = "INSERT INTO SemResDB.dbo.Registration VALUES (" +
                      Integer.toString(nNumAtt) + ",'" + strAreaOfInterest +
                      "','" + strRegName + "')";
         
             //--------------------------------------------------------------------
             // Initialize the database through ADO 
 
             m_ic.putMode(ConnectModeEnum.adModeReadWrite);
             m_ic.Open(strConnect, null, null, CommandTypeEnum.adCmdUnspecified);
             
             // Check for errors - No specific errors are checked in the collection 
             m_Errs = m_ic.getErrors();
             if (m_Errs.getCount() > 0)
             {
                 bSuccess = false;
                 return new Variant(-1);
             }
 
             // Execute the SQL Command "Directly" on SemResDB - ExecDirect equiv.
             m_ic.Execute(strSQL, vRowsAffected, CommandTypeEnum.adCmdText); 
             nRecordCount = vRowsAffected.getInt();
             if (nRecordCount != 1)
             {
                 bSuccess = false;
                 return new Variant(-1);
             }
             
             // Everything looks good
             bSuccess = true;
             return new Variant(Variant.VariantInt,0);
             
         }
         catch (Exception e)
         {
             return new Variant(-1);
         }
         finally
         {
 
             /////////////////////////////////////////////////////
             // DEBUGGING TIP: If debugging from an HTML page as an applet comment 
             // out the following MTx code
             ///////////////////////////////////////////
             // Transaction Server Context Control
             if (bSuccess)        // we are finished and happy
                 ctxObject.SetComplete();
             else                 // we are unhappy
                 ctxObject.SetAbort();
 
             if (m_ic != null)
             {
                 try 
                 {
                     // see is database connection is open, if so close 
                     if (m_ic.getState() == ObjectStateEnum.adStateOpen)
                         m_ic.Close();
                     ComLib.release (m_ic);
                 }
                 catch (Exception e)
                 {
                     return new Variant(-1);
                 }
             } 
         } 
     }    
 }