This sample extends the framework code to show how a middle-tier business object can be invoked through the ADO/WFC component framework. This sample leverages a pre-packaged business object that ships with Remote Data Services (RDS) and Microsoft® Internet Information Server 4.0 (IIS4): the RDSServer.DataFactory. This business object provides data source querying and updates through a business object intermediary, itself. The basic principles employed in this sample are the same as those that would be used in a custom business object. If you plan to use custom business objects written in Java, Visual Basic, or Visual C++, be sure to register the classes properly with the application server, in order that the launch permissions allow objects to be instantiated over HTTP using the Simple Object Access Protocol (SOAP). The simple code sequence needed to invoke and marshal data is shown below.
public boolean run()
{
ObjectProxy obj = DataSpace.CreateObject (
"RDSServer.DataFactory", "http://aServerName");
Recordset rs = (Recordset) obj.call ("Query",
new Object[] {"dsn=aDSN;uid=aUID;pwd=aPWD;database=pubs",
"select * from authors"});
rs.moveFirst();
rs.moveLast();
rs.close();
rs.release();
// VM tip: force garbage collection to
// reclaim heap more efficiently.
System.gc();
System.runFinalization();
return true;
}
To invoke a business object on an application server, you must create a “proxy”; that is, a stand-in for the object that is used to marshal requests and parameters to and from the client’s application process and the remote business object. ADO/WFC layers its ObjectProxy over the RDS SOAP proxy, and can use this proxy to communicate with any Automation-based business object, whether written in Java, Visual Basic, or Visual C++. The following line of code shows how the ObjectProxy is created:
ObjectProxy obj = DataSpace.CreateObject (
"RDSServer.DataFactory", "http://aServerName");
This code creates a new ObjectProxy through the DataSpace class method, CreateObject(prog_id, server_url)
. This proxy may then be used to invoke calls on the target object (in this case the DataFactory) and unmarshal/marshal Recordsets. Once the proxy is created, the method of choice can be invoked through the overloaded call
method:
Recordset rs = (Recordset) obj.call ("Query",
new Object[] {"dsn=aDSN;uid=aUID;pwd=aPWD;database=pubs",
"select * from authors"});
This call passes an Object array of two strings (one containing the ConnectionString, the other the Source/Command) to the proxy. This internally converts the Java types into marshalable Variant data types, packages them into a SOAP request, and dispatches the request to the server-side RDS component. The parameters are then unpacked and the remote object server method (“Query”) is invoked with the parameter values. The resulting Recordset is then packaged into an ADTG stream and marshaled back to the client ObjectProxy, which unpacks the Recordset stream, creates a Recordset instance, populates the Recordset with the unmarshaled tabular data, and then returns a reference to the Recordset to the caller. This process is effectively the equivalent of the original “select * from authors” call, but through the auspices of a business object. Obviously, you can create much more sophisticated, domain-based business objects. Try to program your own Visual Basic Automation class, register it with your application server, and then invoke it with the code provided in this sample.
Return Parameter Limitation (Beta 1)
Currently, the only object type that can be returned from a middle-tier business object is an ADO Recordset. However, any valid OLE Automation types may be used as [in] parameters. This limitation will be removed in subsequent releases of ADO/WFC. The default business object, DataFactory, returns an ADO Recordset as an [out] parameter (return value), which can be used, as is, by application developers. Note that an attempt to return a non-Recordset parameter (return value) will result in a NullPointerException being thrown by the ADO/WFC run time system.