Consuming a Web Service with Powerbuilder 12.5 Classic
“Preliminary” steps in Powerbuilder
This section describes the steps to follow in order to invoke a Web Service.
- Create a new PBL to hold the objects that will be created, especially if you just want to “play around”. In this example it will be SAPDS.PBL.
- Create a new object: on the “Project” tab, select “Web Service Proxy Wizard”
- Check the “Use .Net Engine” checkbox, click Next.
- Indicate the WSDL file URL (see above) and the Assembly Name (e.g. SAPDataServices_Server.dll), then click NEXT.
Note that the Windows SDK for .Net Framework 4.0 must be installed on your system. If that is not the case, you have to do that first:
See the Troubleshooting section further down, if you have issues with this step.
- Select a Service, e.g. “WebService.connection_Operations, click Next
- In the next step, you may set the prefix for the proxy.
The wizard says that by default, it is the portname for each port, but you may leave it empty. In the near future we may decide to set up a naming convention rule for this step.
- Specify the project name and the library where it will be stored:
- You may verify your settings on the “Ready to Create Proxy” window before hitting Finish:
Note that the documentation states that “the assembly is generated in the current target directory”.
- After that, the proxy should be created. Clicking on the “Services…” button opens a window showing the services and structures.
- In the PBL, right-click the generated proxy (e.g. p_ws_sapds) and select “Deploy” to generate the Services and Structures in the PBL:
Invoking Web services through SOAP requires serialization and deserialization of datatypes, and the building and parsing of XML-based SOAP messages. The pbwsclient125.pbx file contains objects for the .NET Web service engine that enable you to perform these tasks without extensive knowledge of the SOAP specification and schema, the XML Schema specification, or the WSDL specification and schema. You can use these objects after you import the extension file into a PowerBuilder Web service application.
- At this point it might be necessary to import a Powerbuilder extension file that should be located in “C:Program Files (x86)SybaseSharedpbwsclient125.pbx“.
Right-click the PBL, select “Import PB Extension…” and select the PB extension file indicated above.
If you’re getting an error message saying that the file is not a valid dll or pbx file you may have an old version of the file “libeay32.dll” loaded.
In my case, through a search with Process Monitor, it appeared that the file libeay32.dll was loaded from C:WindowsSysWOW64 – but it was a very old version (from 2005).
After deleting it, the import process was successful (after the 2nd try) and the following NVOs were generated:
These NVOs are needed, so there’s no point in continuing if this step fails!
The above are necessary “preliminary” steps, next we’ll look at the Powerbuilder code needed to actually invoke a Web Service.
Powerbuilder code to invoke a Web Service
In order to verify the above steps, i.e. to test the Web Service(s), I created a function (f_ws_logon) in a new NVO (n_sap_ds_func) that is invoked through a button click in a very basic window (w_sapds_main).
These objects can be found in the attached PBL (the code was created just to prove the concept, so no need to discuss the naming nor code quality).
In the next section, the code is presented and some additional information given.
Variable declarations, object instantiation
Next, set some values and the Web Service parameters
Set values and Web Service parameters
Finally, the Web Service is called.
|As noted in the comment above, the Web Service is apparently called asynchronously (the fact that there is a “cancelasync” method further supports this assumption).|
Note the comments in the code, as they provide some important additional information!
Finally, the Web Service is called.
Invoke Web Service and handle results, resp. errors
| As noted in the comment above, the Web Service is apparently called asynchronously (the fact that there is a “cancelasync” method further supports this assumption).
The remaining code doesn’t add much (destroying the created objects), so it’s been left out for better lisibility.
Below we have 2 examples of responses with and without ErrorMessage
The LOGON call was obviously successful as it returned the needed session ID.
If the session Id is not provided when calling an SAP Data Service Web Service, the following error message will be displayed (see the CATCH clause):
Debugging a Web Service
I’ve been using SOAPUI or Fiddler.
Installation of the “Windows SDK for Windows 7 and .NET Framework 4” failed on my system for no apparent reason:
The indicated file “SamplesSetupHTMLConfigDetails.htm” was not available. In fact, nothing remained after the failed installation, apparently the installation process deleted all copied/installed files.
The solution was to install the freely available “Microsoft Visual Studio 2010 Express”, because that installs the needed .NET framework.