Novell is now a part of Micro Focus

How to Access Remote ActiveX Controls from NetWare

Articles and Tips: article

Surendra Nath Mohanty
Software Consultant
Novell India Development Center
smohanty@novell.com

01 Dec 2001


This AppNote covers accessing remote ActiveX controls within the Universal Component System (UCS) environment, using the Remote ActiveX Provider. This provider uses SOAP over HTTP to talk to Windows machines and access their ActiveX controls across the Internet.


Topics

ActiveX controls, network application development, Remote ActiveX Provider, scripting languages, Universal Component System (UCS)

Products

Novell SDK

Audience

network administrators, integrators, programmers

Level

advanced

Prerequisite Skills

proficient with Perl, NSN, servlet, and ActiveX usage

Operating System

NetWare 5.x and 6.0, Windows 95/98/NT/2000

Tools

JSDK 2.0

Sample Code

yes

Introduction

As the number of Internet users increases, more services are required for Web applications. Web applications can provide more services by accessing services in the local system as well as on the Internet. To access remote services available on the Internet, there should be some remote mechanism. This AppNote explains a specific remote mechanism used on NetWare to access services available as ActiveX controls in the remote Windows machines.

On NetWare, the Remote ActiveX Provider provides the infrastructure to access remote ActiveX controls from Windows machines. Remote ActiveX Provider is a provider available with the Universal Component System (UCS). UCS provides an interface to different programming languages as well as scripting languages on NetWare to access different component systems. This makes the reusable components available in different component systems.

About the Remote ActiveX Provider

The Remote ActiveX Provider is part of the provider interface of UCS. It allows access to remote ActiveX controls residing on Windows machines. It is based on a master/slave model. The NetWare server from which the request originates acts as the master, and the Windows machine where the controls reside acts as the slave. The architectural model of UCS is shown in Figure 1.

Architecture of the Universal Component System (UCS).

The Remote ActiveX Provider has two modules, UCS2RMT and UCSWIN.

UCS2RMT is a NetWare executable (NLM). It processes the request on NetWare and sends the request to UCS2WIN on the Windows machine. UCS2RMT provides the following functionality:

  • Encodes the request from the script to the SOAP packet and forwards the same to UCS2WIN

  • Decodes the response from UCS2WIN and sends it to the script

UCS2WIN in a Windows executable (EXE). It provides the following functionality:

  • HTTP Listener

  • SOAP Server

  • ActiveX Container

As an HTTP Listener, UCS2WIN waits for the request from the master. After receiving a request, it decodes the same and invokes the appropriate ActiveX control. It encodes the invocation result and sends the response in a SOAP packet.

All About SOAP

The communication between UCS2RMT and UCS2WIN takes place using SOAP (Simple Object Access Protocol) 1.0, a protocol used over HTTP to access objects across the Internet.

SOAP is a lightweight and simple XML-based protocol that is designed to exchange structured and typed information on the Web. The purpose of SOAP is to enable rich and automated Web services based on a shared and open Web infrastructure. SOAP can be used in combination with a variety of existing Internet protocols and formats including HTTP, SMTP, and MIME and can support a wide range of applications from messaging systems to RPC.

SOAP is a way to use the existing Internet infrastructure to enable applications to communicate directly with each other without being unintentionally blocked by firewalls. It does not replace any distributed object protocols, nor is it tied to any single object model. It gives a flexibility to access applications across the Internet.

  • Provides a standard object invocation protocol built on Internet standards, using HTTP as the transport and XML for data encoding

  • Creates an extensible protocol and payload format that can evolve over time

SOAP is meant to be simple. Its specification states that it does not want to "define all aspects of a distributed object system." That means no distributed garbage collection, type safety or versioning, no bi-directional HTTP communications, no message boxcarring or pipeline processing, no object-by-reference, and no object activation.

A simple SOAP packet consists of:

  • HTTP Header

  • SOAP Envelope

  • SOAP Body (payload)

Setting Up the Remote ActiveX Provider

To set up the Remote ActiveX Provider, first download UCS from the Novell Developer Web site at http://www.developer.novell.com/ndk/ucs.htm. Run the setup program on a NetWare server. It will install UCS2WIN.EXE in the server's SYS:PUBLIC\WIN32 folder. Execute the HTTP Listener (UCS2WIN.EXE) on the Windows machine on which you want to utilize the ActiveX controls.

By default, the HTTP Listener uses port 80. If that port is not available because it is being used by another application, you must configure UCS2WIN to use an available port. To do this, follow these steps:

  1. Select Server from the menu.

  2. Select the Properties menu item.

  3. Modify the port and click OK/Apply.

The scripts should be changed to use the specified port in the HTTP Listener. Here is an example of how to change the port to nn:

Set object = CreateObject("OLE:Prog_ID@host_IP_address;nn ")

If the HTTP Listener is using the default port, you do not need to specify the port as shown in this example.

Coding Examples

This section provides examples of how to use the Remote ActiveX Provider from scripting languages such as Perl and Novell Script for NetWare (NSN). It also shows how to access ActiveX controls from a Java Servlet using the Remote ActiveX Provider.

Accessing Remote ActiveX Controls in Perl

This sample uses both UCX components on NetWare and ActiveX controls on a Windows machine. The NetWare UCX component (NWDIR) accesses user information in Novell eDirectory and updates the information in the remote Microsoft Access database using the Remote ActiveX Provider and ActiveX controls.

#Reads NDS users and updates the remote database on the Windows machine. 
#Uses UCS component to read NDS and remote ActiveX control to update the 
#remote database
use PERL2UCS;
$NDS_CONTEXT = "Tree\\Organization"; #NDS tree and Organization
$OU = "Context"; #Context under which we are interested
# DSN information will be included here
$DSN = "DSN=EMPDSN;DefaultDir=D:\\TempWork;DBQ=D:\\TempWork\\MYDB.MDB";
#Change your remote IP address for host_IP_address and progID version with x
$location="OLE:Adodb.Connection.2.x\@ host_IP_address ";
$dir = PERL2UCS->new("UCX:NWDIR") or die "Unable to create  the NWDir object";
$dir->login("userID","passWord");
$databaseobj = PERL2UCS->new($location);
$dir->{"fullName"}="nds:\\\\" . $NDS_CONTEXT . "\\" .$OU; 
$entries = $dir->entries() or die "Not able to get entries \n";
$databaseobj->Open($DSN);
while ($entries->hasMoreElements())
{
   $entry = $entries->next();
   $layout = $entry->{"layout"};
   $attribute= $layout->{"name"};
   if($attribute eq "User")
   {
      $ShortName=$entry->{"ShortName"};
      if(!$ShortName) { $ShortName=" ";};
      $UserEmail=$entry->getFieldValue("Internet EMail Address");
      if(!$UserEmail)  {  $UserEmail=" "; }
      $TelExt=$entry->getFieldValue("Telephone Number");
      if(!$TelExt) { $TelExt=-1;}
      $Title=$entry->getFieldValue("Title");
      if(!$Title)  {   $Title=" "; }
      $SQLINSERT="Insert into Emp(Shortname,Description,Phone,Email)
               values('$ShortName','$Title','$TelExt','$UserEmail')";
      if($databaseobj->Execute($SQLINSERT))
      {
         print "Updated from NDS \n";
      }
      else
      {
         print "Not able to update the infromation \n";
      }
   }
}
$databaseobj->close();

Accessing Remote ActiveX Controls through NSN

This sample creates an Excel spreadsheet on a remote Windows machine using the Remote ActiveX Provider and ActiveX controls. It adds a few items in the spreadsheet and draws a chart according to the items' values.

'******************************************************************************
'  Description: Remote ActiveX Sample to demonstrate the modification of remote
'                Excel spreadsheets
' 1. x should be replaced by a number specific to your installation, by looking
'       into the Windows registry
' 2. host_IP_address should be replaced by the IP address of the Windows machine
' 3. Excel control should be registered in the windows machine.
'******************************************************************************
Dim ProductShortNames (4)
Dim ProductFullNames (4)
Dim ProductAge (4)
On Error Resume Next
Set Excel = CreateObject("OLE:Excel.Application.x@ host_IP_address ")
If (Err.number <> 0 ) Then
   Print ("Unable to create Excel application object")
   Exit Sub
End If
Print "Creating the Active Sheet ..."
Excel.Visible = True
Set Wbs         = Excel.Workbooks
Set Wb          = Wbs.Add()
Set Sheet      = Excel.ActiveSheet
Sheet.Name  = "Novell Scripting Technologies"
ProductShortNames(0) = "Product Short Name"
ProductShortNames(1) = "NSN"
ProductShortNames(2) = "Perl"
ProductShortNames(3) = "SE"
ProductShortNames(4) = "UCS"
ProductFullNames(0) = "Product Full Name"
ProductFullNames(1) = "Novell Script for NetWare"
ProductFullNames(2) = "Perl 5 for NetWare"
ProductFullNames(3) = "ScriptEase for NetWare"
ProductFullNames(4) = "Universal Component System"
ProductAge(0) = "Product Age(Months)"
ProductAge(1) = "36"
ProductAge(2) = "30"
ProductAge(3) = "18"
ProductAge(4) = "12"
Print "Entering the product information ..."
For I = 0 To UBound(ProductShortNames)
   RowNo = I + 1
   Set Cell = Sheet.Range("A" & CStr(RowNo))
   Cell.Value = ProductFullNames(I)
   Cell.Font.Bold = True
   Set Cell = Sheet.Range("B" & CStr(RowNo))
   Cell.Value = ProductShortNames(I)
   Set Cell = Sheet.Range("C" & CStr(RowNo))
   Cell.Value = ProductAge(I)
Next
Print "Completed creation of Excel spread sheet"
Print "Creating Charts"
XlBarClustered = 57
XlColumns = 2
set ChartObj = Sheet.ChartObjects
set AgeChartContainer = ChartObj.Add(200,30,300,200)
Set AgeChart = AgeChartContainer.Chart
geChart.ChartType = XlBarClustered
Set dataRange = Sheet.Range("B2:C5")
AgeChart.setSourceData(dataRange, XlColumns)
AgeChart.Refresh

Accessing Remote ActiveX Controls through a Java Servlet

We have an extension for Java (JAVA2UCS) on NetWare, which helps to access UCS. Once Java can access UCS, it is able to access all services that UCS can access. Accessing remote ActiveX controls is one among them.

This sample servlet accesses a GroupWise control on the remote ActiveX control and sends an e-mail message. The user must provide a GroupWise userID, password, subject, message and the recipient's address. All of these can be supplied to this servlet from a form.

import com.novell.utility.ucs.*;
import java.io.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SendMail extends HttpServlet
{ 
   /**
   * doPost
   *
   * The doPost method is the primary entry point of this servlet.  It is
   * designed to be called as the result of an HTML form post.  This servlet will
   * read and validate the posted parameters, then call the GW control
   * to send e-mail.
   *
   * @param      request    the request object 
   * @param      response    the response object
   * @return     <code>void</void>
   * @exception  IOException problem reading from or writing to
   *             the req or res streams
   */
   public void doPost (
      HttpServletRequest      request,
      HttpServletResponse    response
   ) throws ServletException, IOException
   {
      PrintWriter      out;
      String      title = "Mail Sent";
      String userId    = null;
	  // user id found on form
      String userPw  = null;
	  // password
      String to          = null;
	  // to
      String sub        = null;
	  // subject
      String msg       = null;
	  // message
      userId  = request.getParameter("UserName");
	  // obtain userid data form 
      userPw = request.getParameter("Password");
	  // obtain GroupWise password from form
      to     = request.getParameter("To");
	  // obtain to url from form
      sub    = request.getParameter("Subject");
	  // obtain subject url from form
      msg    = request.getParameter("Message");
      // obtain message url from form 
	  
   // set content type and other response header fields first
   response.setContentType("text/html");
   
   // then write the data of the response
   out = response.getWriter();
   
   out.println("<HTML>");
   out.println("<HEAD><TITLE>");
   out.println(title);
   out.println("</TITLE></HEAD><BODY TEXT=WHITE>");
   out.println("<CENTER><H1><FONT COLOR=RED>" + title +
            "</FONt></H1></CENTER>");
			
try{

      UCSClassFactory cf = new UCSClassFactory();
      //Set the host_IP_address with the windows IP address where GroupWise
      //client is installed
      UCSClass ucsCls  =  cf.getInstance
                        ("OLE:NovellGroupWareSession@host_IP_address");
      UCSObject nwGrpwse = ucsCls.createObject();
      if (nwGrpwse ==null){
                     System.out.println("object not created : ");
                     return;
                  }
				  
      UCSVariable retVal = new UCSVariable();
      UCSVariable argList[] = new UCSVariable[3];
      argList[0] = new UCSVariable(userId);
      //Modify the MAILSERVER with your mail server and PORT with the
      //MAILSERVER's PORT
      argList[1] = new UCSVariable("/ipa-MAILSERVER /ipp-PORT"); 
      argList[2] = new UCSVariable(userPw);
      retVal = nwGrpwse.callMethod("Login",argList); //Authenticates to mail 
      //server
      UCSObject GWRootAccount = retVal.getObject();
       retVal = GWRootAccount.getProperty("WorkFolder");
       UCSObject WorkFolder = retVal.getObject();
      retVal = WorkFolder.getProperty("Messages");
      UCSObject Msgs = retVal.getObject();
      UCSVariable arg = new UCSVariable("GW.MESSAGE.MAIL");
      retVal = Msgs.callMethod("Add", arg);   
      UCSObject Msg = retVal.getObject();
      retVal = Msg.getProperty("Subject");
      UCSObject  Subject = retVal.getObject();    
      UCSVariable PlainText = new UCSVariable(sub); //Adds subject to mail
      Subject.setProperty("PlainText", PlainText);
      UCSVariable BodyText = new UCSVariable(msg); //Adds message
      Msg.setProperty("BodyText", BodyText);
      retVal = Msg.getProperty("Recipients");
      UCSObject recps = retVal.getObject();
      UCSVariable EmailAddr = new UCSVariable(to); // Recipient's email ID
      retVal = recps.callMethod("Add", EmailAddr);
      UCSVariable Priority = new UCSVariable(3); //Normal pripority
      Msg.setProperty("Priority", Priority);
      retVal = Msg.callMethod("Send"); //Sends the mail
   } catch (UCSException e){
                  System.out.println("UCSException");
                  System.out.println(e.getMessage());
           }catch (java.lang.Throwable e){
                  System.out.println("java language exception");
                  System.out.println(e.toString());
         }
   }
}

Conclusion

The Remote ActiveX Provider, a part of UCS, provides access to ActiveX controls residing in remote Windows machines. It uses SOAP over HTTP, which gives access to services available on the network over Internet. Accessing components over the Internet provides greater flexibility. It is a great value proposition for system integrators and solution providers.

For additional information, refer to the following resources:

* Originally published in Novell AppNotes


Disclaimer

The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.

© Copyright Micro Focus or one of its affiliates