Using Portus to access Shared Libraries or DLLs
You can also use Portus to access existing shared libraries or DLLs without any rebuilding or reverse-engineering.
You just need to know the name of the function you wish to call, and what the input and output parmeters look like.
In this HOWTO, we'll build a piece of code into a DLL, and show you how to use Portus to expose a function within this as a Service.
Consider this simple piece of C++ code.
#include <string.h>
#ifdef WIN32
#define PLATFORM_EXPORT __declspec( dllexport )
#else
#define PLATFORM_EXPORT
#endif
extern "C" PLATFORM_EXPORT int calc( char operation[20], int *operand1, int *operand2, int *result );
extern "C" int calc( char operation[20], int *operand1, int *operand2, int *result ){
if( !strcmp( operation, "add" )){
*result = (*operand1) + (*operand2) ;
}
else if( !strcmp( operation, "sub" )){
*result = (*operand1) - (*operand2) ;
}
else if( !strcmp( operation, "mul" )){
*result = (*operand1) * (*operand2) ;
}
else if( !strcmp( operation, "div" )){
*result = (*operand1) / (*operand2) ;
}
else{
*result = 0;
return -1;
}
return 0;
}
This is simple calc method which will take a string, two integers, and return a integer based on the value of string.
For the purposes of this HOWTO, we are running Portus on Windows, and will build the above code into a Windows DLL using MS VC++.
If Portus is running on Linux, the DLL should be built there, and so on, depending on the platform.
A pre-built Windows (x86) DLL is available here
Portus must now be configured to load and run this DLL.
Ideally, our new DLL will be available in the system PATH. On Unix-based
systems, you should change to the directory where the DLL is located, and run
the command export PATH=$PATH:$PWD
. Now restart
Portus in this shell.
On z/OS, ensure the load library containing the DLL is in your STEPLIB concatenation.
As Windows requires a restart before picking up a new system PATH, the simplest thing to do is copy the built DLL into the bin directory of your SOA Gateway installation. Assuming the default installation was used, this will be C:\Program Files\Risaris Limited\Portus {v.r.m}\Apache\bin\ where {v.r.m} denotes the actual Portus server version in use.
Now start your Portus Control Center and choose one of the following methods of creating a Service based on the "calc" example
Download the C-source to your local disk driver from here
See here for how to add/discover a Service.
From the next dialog choose DLL_Driver and click
Enter the Path where you downloaded (or compiled) the "Calc" DLL to. If it is located in a directory available on the search path, leave the Path field empty. Click
Select the demo_dll_calc.dll, click the
buttonYou will now associate the DLL with the source, which will be used to generate the Portus DataView. From the Connect to column's dropdown box select Source from File System.
Advance to the Connect with column, click it, then click the push-button appearing at the right hand corner
In the File Dialog popping up, navigate to the location where the C-source for the demo DLL has been downloaded to, select it
For files with an extension of .c or .h the Language will automatically be set to C. Click the
button.Progress and completion of the generation process will be shown in the Status pane.
The Service has been created and is usable
In the Servers View, right-click on DLL_Driver (or whatever name you might have given it) under Services and select 'Add Service'
In the Properties Viw add the following information
Name : "demo_dll_calc_calc"
Driver : "DLL Driver" (or equivalent on your system)
sharedLib : "demo_dll_calc.dll "( the name of the DLL you've built )
methodName : "calc"
Select the Save button.
Save the following XRD file to disk. This is file which maps the calc functions parameters to a format that Portus can understand.
Open the Navigator View (Window -> Show View -> Navigator).
Right-click your project, and select
Expand File System. Click
and selectClick
and select the directory where you saved the above XRD. Check the XRD, and clickSelect both calcDemo.xsd and calcDemo.xrd. Drag and drop them both onto the demo_dll_calc Service:
Right-click the demo_dll_calc Service and select 'Refresh Service'.
Add a new Service. See here for more information
Add the following information
Name : "demo_dll_calc_calc"
Driver : "DLL Driver" (or equivalent on your system)
sharedLib : "demo_dll_calc.dll "( the name of the DLL you've built )
methodName : "calc"
Right-click on the Service and select 'Publish Service modifications'
Save the following XRD file to disk. This is file which maps the calc functions parameters to a format that Portus can understand.
Open the Navigator View (Window -> Show View -> Navigator).
Right-click your project, and select
Expand File System. Click .
and selectClick
and select the directory where you saved the above XRD. Check the XRD, and clickIn the Server View, right-click your server, and select 'Export Service Definition(s) to server'
Select both the calcDemo files, and click
In the Configuration view, Right-click your Service and select Refresh Service
This section will show you how to access our new DLL Web service.
In the Web Service properties, click the WSDL URL to open your the WSDL for your web service in a browser.
You may import this WSDL to the WS Client of your choice, but for the pupose of this demo, we will use REST-style requests to access the DLL. More information about REST can be found here.
In the browser URL box, remove the ?WSDL characters, and add the following
"?INVOKE&operation=add&operand1=55&operand2=99"
You should get a results something like this
Congratulations! You have now accessed a DLL using Portus
If you look back at the original C program, you can see how the name=value pairs match up to the parameters of the calc function call. Try changing the operation and operands for different mathematical operations.
You can also use a XSL Stylesheet which can be used to change the appearance of the output XML. It is available here. As with the XRD previously, import this file into the project, and export it to the server.
And then ...
Now when you refresh your browser, the stylesheet will be applied and the output should look like this