Welcome!

PowerBuilder Authors: Dan Joe Barry, Carmen Gonzalez, Ian Thain, Yakov Werde, Paul Slater

Related Topics: PowerBuilder, SOA & WOA, .NET

PowerBuilder: Article

Consuming Amazon Web Services Using PowerBuilder and SQL Anywhere 10.0.1

I rolled a little application using SQL Anywhere, PowerBuilder, and Amazon Web Services

An example XML response is shown in code Listing 3. What you need to know is how to return a particular XML node. As mentioned above, this can be done with the XPath query language. It may be helpful to know that "//" represents descendant nodes, the '*' represents any namespace such that //*:'ItemAttributes' finds all such nodes. The WITH clause further selects on child elements based on the root from the XPATH argument (//*:'ItemAttributes'). For example, if we wanted to extract the title, we could use this statement *:Title/text().

You may be wondering how to look at the raw HTTP responses received. This information can be useful for debugging. If you're using SQL Anywhere 10.0.1 build number 3484 or higher you can use the database server command line option -zoc <filename> or set the server option WebClientLogFile. The other alternative is to use a logging tool such as TcpTrace.

Listing 4 is the response to the ItemLookup request using TcpTrace.

Creating a GUI in PowerBuilder
Now that we have our back-end built, we can write a front-end GUI using a RAD development tool such as PowerBuilder. To start things off, open a new workspace in PowerBuilder and name it Amazon. Now, create a new target by choosing File->New->Target and choose application. Finally, create a main window by choosing File->New->PB Object and choose window. We now have all the elements needed for a basic project setup and simply need to add code to tie them together. To do this, you will have to add the code shown in Listing 5 to your application object's open event.
With that in place we can go about adding elements to our main window. A single line edit will be provided to allow the user to enter a new UPC. The information gathered here will be used in the call to our stored procedure that will populate a datawindow containing bibliographical information. To view the latter, add a datawindow control. Finally, to fire the whole process off, drop down a command button. The finished layout is shown in Figure 4.

The workhouse of the GUI is the datawindow, since it's going to do all the work of invoking the stored procedure we created earlier. To create it, go to File->New->Datawindow->FreeForm. When prompted for your data source, make sure you choose Stored Procedure. From there, you'll get to choose the function or procedure you want to invoke. In our case, choose the ItemLookupWrapper procedure. Complete the creation of the object by stepping through and accepting all the defaults until you complete the process by clicking the Finish button.

Making the Call
Having put all the work of calling the Amazon Web Service in a stored procedure on the database side, calling it out of PowerBuilder is trivial. Other than the database connection and the creation of the datawindow object, you only need two lines of code! The first is a call to set your transaction object and the other retrieves whatever UPC the user has entered.

The first call can be put in the open event of your main window and is simply:

dw_1.SetTransObject(SQLCA)

The second call is needed to invoke the stored procedure and can be put in the clicked event of a cb_ok button like this:

dw_1.Retrieve(sle_1.Text)

Finished Product
Figure 5 shows the finished product. Key in a UPC and with the help of PowerBuilder, SQL Anywhere and Amazon Web Services you have just rolled your own media organizer!

Conclusion
Calling Web Services out of SQL Anywhere opens up a whole new world of programming fun. Coupled with this arsenal and an excellent RAD development tool such as PowerBuilder, you can be up and coding your own Web Service clients in no time at all. I encourage you to start exploring!

Next Time
In this segment we looked at consuming Web Services from SQL Anywhere. In the next article in this series, we'll look at exposing them. In doing so, we will go about building our own mini-version of an Amazon-like Web Service using the data we collected in this part.

References
-   Amazon API Documentation http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=19.
-   SQL Anywhere Documentation www.ianywhere.com/developer/product_manuals/sqlanywhere.
-   SQL Anywhere Developer Edition http://eshop.sybase.com/eshop/try_buy.
-   PowerBuilder Evaluation Copy http://eshop.sybase.com/eshop/try_buy.
-   Inside SOAP www.xml.com/pub/a/2000/02/09/feature/index.html.

More Stories By Deanne M. Chance

Ms. Chance graduated in 1996 with a degree in computer science from the University of Illinois. She has been a frequent contributor to the PowerBuilder Developer's Journal and gave a key presentation at Sybase TechWave 2005 entitled "A Real-Time Physical Inventory Solution Using PocketBuilder ASA and a WiFi Connection." She has held several engineering positions, starting a career at Motorola where she focused on mobile I.P. by doing real-time embedded programming for the base radio controller group as part of the iDEN/Nextel project.

Comments (0)

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.