Blog Feed Post

Creating .NET Web Services with PB11.5

Back in January, I showed how easy it was to consume SOAP-based web services with PowerBuilder 11.5.  PowerBuilder supports the .NET web services engine, which allows PB apps to invoke very complex web services with very little of the detailed coding required for a similar C# or VB.Net application. The Web Services Proxy wizard parses the WSDL for the service, and automatically creates a proxy object and all the necessary structures and parameter definitions that represent the service’s operations and request/response structures.  Once those are created, the code required to invoke a service and parse the resulting data is extremely simple.

This posting will look at the other side of the equation – using PowerBuilder to create and publish a .NET web service to an Internet Information Services (IIS) instance. We’ll also see just how easy it is to test and debug that service with the PB integrated debugger.

Taking it up a notch

Most of the web service examples I’ve seen have been really limited in functionality, and I’m sure you’ve seen them as well… For example, pass in a ticker symbol and get the current stock quote. Pass in a zip code and get the current time and temperature. YAWN!!!  While those are good at teaching the basics of the SOAP plumbing, most “real world” web services are rarely that simple, and usually require a much more complex XML schema in the request or response message.

You basically have two options when dealing with very complex XML in a SOAP message:

Marshall the resultset into an XML document within the service, and pass it back as a single long string.

This forces the recipient to parse the response using MSXML, or the System.XML classes to extract the data they need. What you end up with is a web service with absolutely no “metadata” in the WSDL that can help the consumer understand the content.

Create a set of strongly-typed structures that accurately represent the data being returned.

This allows the .NET web services engine to create meaningful WSDL for the SOAP-based service.  With this approach, the WSDL contains actual metadata about the request and/or response structure, and the consumer can better understand the nature of the data being returned.

This example will use the second approach, and return a complex, nested hierarchical resultset from a PowerBuilder .NET web service.  We’ll use the “EAS Demo DB 115″ database that ships with PowerBuilder 11.5.

Step 1: Create the .NET Web Service target

You can use an existing workspace, or create a new one.  Once you have that, select File > New and select the Target tabpage.  We’re creating a .NET Web Service target from scratch, so select that path through the Wizard.

  1. Create from scratch
  2. Project name, Library location, and Target name:  I selected OrdersByCustID_ws for mine.
  3. Library search path: accept the default.
  4. PowerBuilder object name: This is the NVO that will be created, and I called mine n_ordersByCustID.
  5. Web Service virtual directory name:  This is the folder location within your local IIS instance where the compiled service objects will be placed.  I selected OrdersByCustID.
    The Web Service URL Preview is an .ASMX page that allows you to test your compiled service.  We’ll use that later.
  6. Resource file and directory list: This is where you’d list image files, 3rd-party .NET DLLs, etc., that your Web Service target will use.  We won’t have any, so just click NEXT.
  7. Win32 Dynamic Library File list:  Again, we won’t be using any, so just click NEXT.
  8. Directly deploy to IIS:  The default server name is “localhost”.
  9. Click FINISH, and you’ve got your target, project object, and nonvisualobject class created in your PBL.

Step 2: Design the Web Service

The first thing you ask is, “What question am I being asked, and what will the answer look like?”  For this example, I designed a query that answers a very basic sales question:  Show me the complete order history for a specific  customer between any two dates.”  The inputs to this question are the customer ID, and the desired From and To dates.  The output will be a nested hierarchy that looks sort of like this pseudo-XML structure:


For a single customer, retrieve some basic customer information (ID, name, city, state, zip). For each sales_order whose Order_Date is between the From and To date, retrieve the Order_ID, and the Order_Line_Items.   Here’s a picture of the datawindow painter SQL source for that query:

Sales report query

Now, I could take this “hierarchical”-style query, construct grouping levels in the datawindow and use the native XML properties of the datawindow to persist an XML representation of the resultset.  But that would give me Option 1 above, a single string containing the XML data without metadata in the WSDL, and I don’t want that!  What I’m going to do is create three Structure classes that represent the three “levels” of this query, Customer, Order and Order_Line_Item.

The Customer structure will have an attribute which is an array of Order structures, and the Order structure will have an attribute which is an array of Order_Line_Items.  The public method in the nonvisualobject will take three input parameters (custID, fromDate, and toDate), and its return value will be the outer Customer structure.

Here’s a picture of the three Structure classes I’ve created.  You can clearly see how I’ve nested an array of s_order_line_item within the s_sales_order structure, and an array of s_sales_order within s_orders_by_custid.

Result set structures

Step 3: Create the public method within the NVO

This will be the Operation that gets exposed in your WSDL, so choose a name for the method and its arguments that will give the consumer some indication of their meanings.  I chose:

getOrdersByCustID( long al_custID, date ad_from, date ad_to) returns s_orders_by_custid

The code in that method is really pretty simple.  I won’t recreate it here, but you can download the entire example here and review the code yourself.  It basically just instantiates a datastore, retrieves the data, and moves the data row by row, column by column into a local variable that matches the output structure.  The NVO also needs to connect and disconnect from the database, and I placed the code for this in the Constructor and Destructor events, respectively.

Remember that ANY public method or instance variable will be available to be exposed through the web service.  If you create additional methods within the NVO (and my example has both an of_connect() and an of_disconnect() method), then these should be scoped as PRIVATE.  The same goes for Instance variables.  Make them Private, and if you want to expose them, create public Get/Set methods for them.

Step 4: Complete the Project Object and Deploy the Web Service

The most important section of the Web Service Project object is on the Objects tab.  This is where you select the NVO and the methods in that NVO that will be exposed as part of the Web Service.  In the future, you may have web service targets with multiple PBLs, containing multiple NVOs, but this example has one of each.  In the Custom Class Objects treeview, select the n_ordersbycustid object.  Then select the checkbox next to the getOrdersByCustID method in the list of available methods.  Then save the changes to the Project object, and click the Deploy button.  If all goes well, the output window should give you a success message when the service is deployed to IIS.

The Objects tab also allows you to view the WSDL that will be generated for your service (NOTE: some browsers handle this better than others – IE8 seems to work fine, but Google Chrome does not.)  You can also click the Run Web Service button to launch a simple .ASMX page that allows you to test the service.  Let’s do that now!

Step 5: Test the Web Service

Click the Run Web Service button.  This launches the .ASMX page that shows the NVO name, and a link to any exposed methods within the class.  It looks like this:

ASMX Test Page

Click the link to getordersbycustid, and you’ll be prompted to enter values for the input parameters.  You also see the WSDL, presented in the different available W3C versions.  Now, the data in the EAS Demo DB is getting quite old, so you’ll find that order dates are back in the 2003-2006 timeframe.  Use the following values:

  • Customer ID = 101;
  • From Date = ‘2003-01-01′;
  • To Date = ‘2004-12-31′

Then click Invoke to run the service.  If everything works correctly, a new Internet Explorer window will open and present the XML result from the service.  If that doesn’t happen, you can actually run the PowerBuilder debugger and step through the lines of code in the method as it’s running!

Open the debugger and place a breakpoint at some line of code inside the getOrdersByCustID method, say the point where it executes the Retrieve() function.  Then click the “Start Debugger” button.  Now go back to the ASMX page and re-click the Invoke button.  The PB Debugger will stop on your breakpoint, and you can begin step-by-step debugging, examine local, instance, or global variables, set watch variables, etc…

So, PowerBuilder 11.5 can be an integral part of your Service Oriented Architecture, as both a consumer AND a producer of complex SOAP-based web services.   And again, you can download the entire example I’ve just created here.



Read the original blog entry...

More Stories By Paul Horan

Paul Horan is a Senior Solution Advisor and Mobility Architect at SAP, and works with the SAP Mobile Platform and SAP Mobile Secure product lines. Paul joined SAP as part of their acquisition of Sybase in June, 2010. Prior to that, Paul worked for Sybase as a technical pre-sales architect supporting PowerBuilder, PowerDesigner, and SQL Anywhere. Paul works out of SAP's Reston VA office. A 1984 graduate of Indiana University, Paul currently resides in Arlington VA.

Latest Stories
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
DXWorldEXPO LLC announced today that "Miami Blockchain Event by FinTechEXPO" has announced that its Call for Papers is now open. The two-day event will present 20 top Blockchain experts. All speaking inquiries which covers the following information can be submitted by email to [email protected] Financial enterprises in New York City, London, Singapore, and other world financial capitals are embracing a new generation of smart, automated FinTech that eliminates many cumbersome, slow, and expe...
Evan Kirstel is an internationally recognized thought leader and social media influencer in IoT (#1 in 2017), Cloud, Data Security (2016), Health Tech (#9 in 2017), Digital Health (#6 in 2016), B2B Marketing (#5 in 2015), AI, Smart Home, Digital (2017), IIoT (#1 in 2017) and Telecom/Wireless/5G. His connections are a "Who's Who" in these technologies, He is in the top 10 most mentioned/re-tweeted by CMOs and CIOs (2016) and have been recently named 5th most influential B2B marketeer in the US. H...
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
The best way to leverage your Cloud Expo presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering Cloud Expo and @ThingsExpo will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at Cloud Expo. Product announcements during our show provide your company with the most reach through our targeted audiences.
DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held November 11-13, 2018, in New York City. Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of bus...
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City and will bring together Cloud Computing, FinTech and Blockchain, Digital Transformation, Big Data, Internet of Things, DevOps, AI, Machine Learning and WebRTC to one location.
DXWorldEXPO LLC announced today that ICOHOLDER named "Media Sponsor" of Miami Blockchain Event by FinTechEXPO. ICOHOLDER give you detailed information and help the community to invest in the trusty projects. Miami Blockchain Event by FinTechEXPO has opened its Call for Papers. The two-day event will present 20 top Blockchain experts. All speaking inquiries which covers the following information can be submitted by email to [email protected] Miami Blockchain Event by FinTechEXPO also offers s...
@DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held November 11-13, 2018, in New York City. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises - and delivering real results.
The dynamic nature of the cloud means that change is a constant when it comes to modern cloud-based infrastructure. Delivering modern applications to end users, therefore, is a constantly shifting challenge. Delivery automation helps IT Ops teams ensure that apps are providing an optimal end user experience over hybrid-cloud and multi-cloud environments, no matter what the current state of the infrastructure is. To employ a delivery automation strategy that reflects your business rules, making r...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
"We started a Master of Science in business analytics - that's the hot topic. We serve the business community around San Francisco so we educate the working professionals and this is where they all want to be," explained Judy Lee, Associate Professor and Department Chair at Golden Gate University, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...