Welcome!

PowerBuilder Authors: Dan Joe Barry, Ian Thain, Yakov Werde, Paul Slater, Bruce Armstrong

Related Topics: PowerBuilder

PowerBuilder: Article

Prognos with DataWindow.NET 2.0 and PowerBuilder 11 Web Services

Calculate Your Scholarship Online

In preparing the last page, a calculation of a possible scholarship is done. Here the PowerBuilder Web Service is called in ASP.NET on the server and not through AJAX on the browser.

We also make use of a handy JavaScript library called Behaviour. It lets you separate the JavaScript code from the design. This means the designer can create the page without touching the JavaScript. The script is applied during the rendering of the page in the browser. The following code shows the definition of what should happen if the ForwardButton gets clicked.

'.ForwardButton' : function(element){
    element.onclick = function(){
       pf.GoToNextPage('forward');
    }
},

The Back-End
Creating Web Services with PowerBuilder 11 is very easy. We copied the classes needed from the PowerBuilder 10.5 application and created a wrapper NVO for all the access logic. After this we created a .NET Web Service target and did the appropriate settings in this project painter. You can choose one or more objects to be used as a Web Service and you can give each object a Web Service name. Choose the methods you'd like to publish and name them the way you want it to be seen from the outside (see Figure 3).

You can run a test page directly from the project painter. There you can call each of the methods of the service and see some sample script on how to include it into your application.

Using .NET Assemblies in PowerBuilder
We store some access and text information in XML files that are used from the PowerBuilder part of the application and from the ASP.NET 2.0 part as well. As PBDOM is not an option when generating .NET applications we made use of the XML classes in the .NET Framework.

The Microsoft .NET Framework is a huge framework and class library you can make use of. It replaces the old Windows API with an object-oriented component-based API. It includes functionality for file handling, XML parsing, security, communication, and database access. For more details follow the link for the .NET Framework in the reference section below.

We made use of the various XML classes from the framework. To give you an idea, I included a couple of code lines for XML handling.

The method LoadXml loads a string into an XMLDocument. Using an XPath expression with the method SelectNodes returns an XMLNodeList you can work with.

string ls_String, ls_User
...
#if defined pbdotnet then
    System.Xml.XmlDocument xmlDoc
    System.Xml.XmlNodeList xmlElements
    xmlDoc = create System.Xml.XmlDocument
    xmlDoc.LoadXml( ls_String )
    xmlElements=doc.SelectNodes &
       ("//n1/n2[@name='"+ls_User+"']/*");
#end if

Some rules concerning the script:
• Although using .NET classes, you have to use PowerScript syntax. If you're used to writing C# it's quite strange at the beginning.
• To create a class the keyword create is used, not the keyword new as in C#.
• Compound statements like if, case, and for are used as in PowerScript.
• PowerScript variables can be declared outside the .NET code and can be accessed in the code.
• Don't forget to include the mscorlib.dll in the .NET Assemblies tab of the target properties

To compile platform-specific logic, PowerBuilder 11 introduced conditional compilation. You can distinguish between PBNATIVE, PBWEBFORM, PBWINFORM, PBWEBSERVICE, PBDOTNET, and DEBUG. The .NET-specific preprocessor symbols tell PowerBuilder to ignore everything between #if defined and #end if when you save your object in the painter. That program code will be checked only when the .NET target is generated.

When it comes to debugging the server part, PowerBuilder 11 does a brilliant job. You can define breakpoints and start the debugger in PowerBuilder as usual. As soon as a PowerBuilder Web Service is called the PowerBuilder IDE pops up. You can single step through PowerBuilder and .NET code and look at variables used in PowerScript and variables defined in the .NET code only. In the listing above you can inspect the variable ls_String and check the properties of the xmlDoc variable.

Conclusion
With PowerBuilder 11 and DataWindow.NET, Sybase provides two tools to write applications for the Web. It lets you reuse PowerBuilder business logic. With PowerBuilder 11 it's possible to deploy PowerBuilder business logic to IIS very easily. This is something you have been able to do with EAServer for quite some time. And since the PowerBuilder Application Server Plugin is available you can do this with other application servers as well. You can even use the Microsoft Visual Web Developer 2005 Express Edition (which is free) for programming with DataWindow.NET.

References
• DataWindow.NET and PowerBuilder 11.
www.sybase.com.
• Microsoft Visual Web Developer 2005 Express Edition. http://msdn.microsoft.com/vstudio/express/vwd/.
• Microsoft .NET Framework. http://msdn2.microsoft.com/en-us/netframework/aa569294.aspx.
• AJAXWorld Conference.
www.ajaxworldconference.com.
• Dave Crane et al. "AJAX in Action."
www.manning.com/crane.
• Ben Nolan. "Behaviour."
www.bennolan.com/behaviour/.
• Prognos. www.ausbildungsbeitraege.info.

More Stories By Arthur Hefti

Arthur Hefti is CEO of CATsoft Development GmbH in Zurich. He has been working with PowerBuilder since version 3 and taught dozens of PowerBuilder training classes. He and his team create custom-made client/server and Web applications using XML, Web Services, and encryption.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Alan 06/21/07 09:59:26 AM EDT

I think this is a very trivial application and it should not be talked about in pbdj even if it is for the sake of showing a technical argument.

Seems more like an addvertisemt !! The whole app would take no longer than 3 days of work !! Writting the word Switzerland does not make it a high end contrinution :-)