Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 3 Using OIG for .NET : Code Examples

Code Examples
Example 1
The following code fragments show the Page_Load method of a sample ASPX page. The page contains a single web control, a ListBox named listBooks. A non-pooled session is opened and the BOOKLIST XML document is called to return the data in the BOOKS TIBCO Object Service Broker table. The GetTable method is used to extract the data as an ADO.NET DataTable object. A “For Each” loop is used to extract the values of the TITLES attribute so that they can appear in the ASPX page’s ListBox.
Visual Basic
Private Sub Page_Load( _
   ByVal sender As System.Object, _
   ByVal e As System.EventArgs) _
   Handles MyBase.Load
   Dim eSession As eCTSnet.eCTSsession = New eCTSnet.eCTSsession
   Dim sessParms As Hashtable = New Hashtable
   Dim row As DataRow
   sessParms("U") = "USR40"
   sessParms("P") = "USR40"
   sessParms("HOST") = "USR40"
   eSession.OpenApplication(sessParms)
   eSession.RunXmlDoc("BOOKLISTNET")
   Dim table As DataTable =    eSession.GetTableFromDocument("BOOKLISTNET")
   For Each row In table.Rows
      listBooks.Items.Add(row("TITLE"))
   Next
   eSession.Dispose()
   eSession = Nothing
End Sub
C#
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using eCTSnet;
namespace OIGDocExamp
{
   /// <summary>
   /// Summary description for WebForm2.
   /// </summary>
   public class WebForm2 : System.Web.UI.Page
   {
      protected System.Web.UI.WebControls.ListBox listBooks;
   
      private void Page_Load(object sender, System.EventArgs e)
      {
         // Put user code to initialize the page here
         eCTSsession eSession = new eCTSnet.eCTSsession();
         Hashtable sessParms = new Hashtable();
         sessParms.Add("U", "USR40");
         sessParms.Add("P", "USR40");
         sessParms.Add("HOST", "USR40");
         eSession.OpenApplication(sessParms,
            eCTSnet.eCTSsession.Mode.Pooled);
         eSession.RunXmlDoc("BOOKLISTNET");
         DataTable dt =          eSession.GetTableFromDocument("BOOKLISTNET");
         foreach (DataRow row in dt.Rows)
            listBooks.Items.Add( (string)(row["TITLE"]));
         eSession.Dispose();
      }
      #region Web Form Designer generated code
      override protected void OnInit(EventArgs e)
      {
         // CODEGEN: This call is required by the ASP.NET Web Form Designer.
         InitializeComponent();
         base.OnInit(e);
      }
      
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         this.Load += new System.EventHandler(this.Page_Load);
      }
      #endregion
   }
}
Example 2
This example shows how you create an ASP.NET web service in Microsoft Visual Studio .NET, using the .NET class library for OIG.
First, open Visual Studio and create a new project. For the project type, select Visual Basic. For the template, select ASP.NET Web Service.
In the new project, add a reference to the .NET class library for OIG.
Next, in the generated .asmx file, add the following Visual Basic code:
<WebMethod()> Public Function GetBookDetails(ByVal BookID As String) _
As DataTable
   Dim oSession As eCTSnet.eCTSsession = New eCTSnet.eCTSsession
   Dim userParms As NameValueCollection = New NameValueCollection
   oSession.OpenApplication()
   userParms("KEY") = BookID
   oSession.RunTrans("BOOKDETADO", userParms)
   GetBookDetails = oSession.GetTable()
   oSession.Dispose()
   oSession = Nothing
End Function
Compile and run the project. In debug mode, the project presents a web-based interface that you use to test the web service.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved