Thursday, February 28, 2013

Using .NET Assemblies with PowerBuilder

The archive of my PowerBuilder.TV webcast on Using .Net Assemblies with PowerBuilder is available.  This webcast demonstrates:

  • How to use non-visual assemblies in PowerBuilder Classic Win32 targets (any version) using COM Callable Wrappers (CCWs)
  • How to use visual assemblies in PowerBuilder Classic Win32 targets (any version) with assistance from theMicrosoft Interop Forms Toolkit
  • How to use non-visual assemblies in PowerBuilder Classic WinForm and WebForm targets using conditional code blocks
  • How to use non-visual assemblies from PowerBuilder.NET

Note that a PowerBuilder.TV account (which is free of charge) is required to access the webcast.  It was a repeat of the session I gave at the PowerBuilder Developer Conference that was co-hosted with SAP TechEd 2012.  The sample code used as well as the PowerPoint slides are available on my Google Drive.

Creation and Consumption of Web Services with PowerBuilder

The archive of the first of two of my PowerBuilder.TV webcast on the Creation and Consumption of Web Services with PowerBuilder is available.  The webcast examines some of the recent improvements in PowerBuilder 12.5 for the creation and consumption of web services, with emphasis on:

  • The new WCF client in PowerBuilder.Net
  • The new WCF service type in Powerbuilder.Net
  • The new REST client in Powerbuilder.Net

Note that a PowerBuilder.TV account (which is free of charge) is required to access the webcast.  It was a repeat of the session I gave at the PowerBuilder Developer Conference that was co-hosted with SAP TechEd 2012.  The sample code used as well as the PowerPoint slides are available on my Google Drive

The second webcast focused on providing WCF capability in PowerBuilder Classic by wrapping the WCF Client created in PowerBuilder.Net in a .Net assembly created in PowerBuilder.Net and then accessing that through a COM Callable Wrapper (CCW).  A link to that archive of that presentation will be provided as soon as it is available.

Saturday, February 23, 2013

Using PowerBuilder.Net Visual Components in WPF Browser Applications

In an earlier blog post I demonstrated how you can create visual components in PowerBuilder.Net and then use them from within Visual Studio (including the Express version that you can download free of charge from Microsoft).  What I created in Visual Studio for that demonstration was a WPF application, but there are other things you can do with PowerBuilder.Net visual components when you get them into Visual Studio.  One of those is to create a WPF Browser Application.

WPF Browser Application (also called 'XBAP', short for XAML Browser Application) is a method of running WPF applications within a browser and still maintain rich client functionality.  Think of it as the half way point betweenClickOnce (in which the application is simply distributed through the browser, but runs independently on the local machine) and SilverLight (where the application runs within the browser).  An XBAP application runs 'within' the browser to the extent that it uses it as the host that it displays in, so it appears to be a web application.  Like ClickOnce, it requires that the .Net Framework is was written referencing be deployed on the client, and will prompt the user to install it if it is not available.

In order to run XBAPs within Internet Explorer you must first customize one of the security settings to enable them.  The plugin that allows XBAPs to run within Firefox is distributed with .Net Framework 3.5.  Once it is installed, adding the location to it to the system path then enables Chrome and Opera to run XBAPs as well.  This site provides extensive details on getting the various browsers configured correctly.

XBAPs normally operate under partial trust.  However, depending on what your application needs to do you may need to elevate it's permissions to allow it to operate under full trust.  This site provides detains on enabling an XBAP to run under full trust.  For the sample app I used in that demo I needed to configure the XBAP to run under full trust because I wanted to do a binding redirect on the Oracle ODP.Net libraries and a binding redirect requires full trust.

Note that you will need to use PowerBuilder 12.5.1 (the maintenance release, not the original 12.5 release) in order to create the visual component.  One of the significant enhancements in that maintenance release was support forcompiling applications and components to support x64 and AnyCPU targets.  Assemblies created for use in XBAP applications have to target AnyCPU.

Having said all that, here's what the sample component looks like when compiled as an XBAP and then accessed via Internet Explorer:


Here's the same XBAP being accessed from Firefox:

From Chrome:

And finally from Opera:


Tuesday, February 19, 2013

How to create Visual Components in PowerBuilder for Visual Studio Developers

Another of the latest videos from the SAP Database and Tools Academy (

The video is pretty much self explanatory.  Just reiterate the main points here and provide some of the sample code.

1.  Create a .Net assembly target and select CustomVisual as the object type to be created.
2.  Create your visual user object in the WPF panel that is presented.
3.  Go to the Objects tab on the project and make sure you select the visual component you want to deploy.
4.  In addition to the assembly containing your visual component, PowerBuilder will place the following runtime assemblies in the output folder.  Give all of them to the Visual Studio developer.

  2. Sybase.DataWindow.Common.dll  
  3. Sybase.DataWindow.Core.dll  
  4. Sybase.DataWindow.Interop.dll  
  5. Sybase.DataWindow.Shared.dll  
  6. Sybase.DataWindow.WPF.dll  
  7. Sybase.PowerBuilder.Common.dll  
  8. Sybase.PowerBuilder.Common.xml  
  9. Sybase.PowerBuilder.Compiler.Assist.dll  
  10. Sybase.PowerBuilder.Core.dll  
  11. Sybase.PowerBuilder.Core.xml  
  12. Sybase.PowerBuilder.DataSource.Db.dll  
  13. Sybase.PowerBuilder.DataSource.dll  
  14. Sybase.PowerBuilder.Interop.dll  
  15. Sybase.PowerBuilder.WPF.Controls.dll  
  16. Sybase.PowerBuilder.WPF.Controls.Skins.dll  
  17. Sybase.PowerBuilder.WPF.Controls.xml  
  18. Sybase.PowerBuilder.WPF.dll  
  19. Sybase.PowerBuilder.WPF.xml  

5.  The visual studio developer will create a reference in their Toolbar to the new WPF control by selecting Choose Items... and then using the Browse option under WPF control to navigate to your assembly and then select the visual control within it.
6.  The Visual Studio developer can now drop the PowerBuilder visual object onto a WPF window in their application.  There may be a couple of errors the first time they attempt to compile the application:
a.  If the WPF application has been created with a Target Framework Reference of ".Net Framework 4 Client Profile" they will need to change it to ".Net Framework 4".  The assembly that PowerBuilder created indicates it has a dependency on System.Web, which is not included in the Client Profile version of the target framework.
b.  When the Visual Studio developer added your component to their WPF window, Visual Studio automatically added a reference to it to the project.  The Visual Studio developer will also need to add an explicit reference to Sybase.PowerBuilder.WPF.Controls to the project.

If you are incorporating a DataWindow control in your custom visual user object, you will need to make a few additional changes.

1.  Assuming that you are going to be using ADO.Net to connect to the database, you will need to provide these additonal runtime assemblies to the Visual Studio developer.  Note that PowerBuilder will not automatically copy them to the output folder for you.

  1. Sybase.PowerBuilder.ADO.dll  
  2. Sybase.PowerBuilder.DataSource.Db2.dll  
  3. Sybase.PowerBuilder.DataSource.Sharing.dll  
  4. Sybase.PowerBuilder.Db.dll  

Also note that the following runtime assemblies will also need to be given to the Visual Studio developer, because the DataWIndow uses them to read SRD files:

  1. antlr.runtime.dll  
  2. Antlr3.Runtime.dll  

2.  The Visual Studio developer will need to add explicit references to the antlr3.runtime.dll and Sybase.PowerBuilder.DataSource.Sharing.dll assemblies.

3.  If you want to have the Visual Studio developer pass in an established connection to the database and have the DataWindow within the PowerBuilder component use it instead of establishing it's own seperate connection to the database, you'll need to add a method to the custom visual user object that takes an argument of System.Object and then uses the SetAdoConnection method on the transaction object to assign that argument as a proxy connection.  For example:

  1. boolean  lb_rc  
  2. integer  li_rc  
  3. try  
  4.   SQLCA.DBMS = "ADO.Net"  
  5.   SQLCA.DBParm = "Namespace='Oracle.DataAccess.Client'"  
  6.   lb_rc = sqlca.SetAdoConnection(a_conn)  
  7.   if not lb_rc then  
  8.     MessageBox ( "Error", "SetAdoConnection failed" )  
  9.     return -1  
  10.   else  
  11.     connect using sqlca ;  
  12.     if sqlca.SQLCode <> 0 then  
  13.       MessageBox ( "Error", "Connect failed: " + sqlca.SQLErrText )  
  14.       return -1  
  15.     else  
  16.       li_rc = dw_1.SetTransObject ( sqlca )  
  17.       if li_rc < 0 then  
  18.         MessageBox ( "Error", "SetTransObject failed" )  
  19.         return -1  
  20.       else  
  21.         return 1  
  22.       end if  
  23.     end if  
  24.   end if  
  25. catch ( Throwable e )  
  26.   Exception exp  
  27.   exp = create Exception  
  28.   exp.SetMessage(e.GetMessage())  
  29.   throw exp  
  30. end try  

4.  The Visual Studio developer then creates a proxy object based on the IAdoConnectionProxy interface, create it based on AdoConnectionProxy, assigns the connection and transaction to it, and passes into your method on the custom visual user object.

  1. short rc;  
  3. String connectString = "Data Source=//oracle:1521/orcl;User Id=scott;Password=tiger2";  
  4. Oracle.DataAccess.Client.OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection(connectString);  
  5. conn.Open();  
  6. Oracle.DataAccess.Client.OracleTransaction trans = conn.BeginTransaction();  
  8. Sybase.PowerBuilder.DataSource.Sharing.IAdoConnectionProxy proxy;  
  9. proxy = new Sybase.PowerBuilder.DataSource.Sharing.AdoConnectionProxy();  
  11. proxy.Connection = conn;  
  12. proxy.Transaction = trans;  
  14. rc = u_customvisual1.AssignConnection(proxy);  

5.  Note that when you have methods you want to expose on the custom visual user object, you select those rather than the custom visual user object in the project painter, so that PowerBuilder knows it needs to expose those methods on the control in the assembly.