SYS-CON MEDIA Authors: Yeshim Deniz, Pat Romanski, Gary Arora, Zakia Bouachraoui, Liz McMillan

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:

<Customer>
     <Sales_Order>
          <Sales_Order_Line_Item/>
          <Sales_Order_Line_Item/>
    </Sales_Order>
    <Sales_Order>
        <Sales_Order_Line_Item/>
        <Sales_Order_Line_Item/>
    </Sales_Order>
 </Customer>

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.

Enjoy!

-Paul-

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
While a hybrid cloud can ease that transition, designing and deploy that hybrid cloud still offers challenges for organizations concerned about lack of available cloud skillsets within their organization. Managed service providers offer a unique opportunity to fill those gaps and get organizations of all sizes on a hybrid cloud that meets their comfort level, while delivering enhanced benefits for cost, efficiency, agility, mobility, and elasticity.
Isomorphic Software is the global leader in high-end, web-based business applications. We develop, market, and support the SmartClient & Smart GWT HTML5/Ajax platform, combining the productivity and performance of traditional desktop software with the simplicity and reach of the open web. With staff in 10 timezones, Isomorphic provides a global network of services related to our technology, with offerings ranging from turnkey application development to SLA-backed enterprise support. Leadin...
DevOps has long focused on reinventing the SDLC (e.g. with CI/CD, ARA, pipeline automation etc.), while reinvention of IT Ops has lagged. However, new approaches like Site Reliability Engineering, Observability, Containerization, Operations Analytics, and ML/AI are driving a resurgence of IT Ops. In this session our expert panel will focus on how these new ideas are [putting the Ops back in DevOps orbringing modern IT Ops to DevOps].
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
Enterprises are striving to become digital businesses for differentiated innovation and customer-centricity. Traditionally, they focused on digitizing processes and paper workflow. To be a disruptor and compete against new players, they need to gain insight into business data and innovate at scale. Cloud and cognitive technologies can help them leverage hidden data in SAP/ERP systems to fuel their businesses to accelerate digital transformation success.
Concerns about security, downtime and latency, budgets, and general unfamiliarity with cloud technologies continue to create hesitation for many organizations that truly need to be developing a cloud strategy. Hybrid cloud solutions are helping to elevate those concerns by enabling the combination or orchestration of two or more platforms, including on-premise infrastructure, private clouds and/or third-party, public cloud services. This gives organizations more comfort to begin their digital tr...
Most organizations are awash today in data and IT systems, yet they're still struggling mightily to use these invaluable assets to meet the rising demand for new digital solutions and customer experiences that drive innovation and growth. What's lacking are potent and effective ways to rapidly combine together on-premises IT and the numerous commercial clouds that the average organization has in place today into effective new business solutions.
Keeping an application running at scale can be a daunting task. When do you need to add more capacity? Larger databases? Additional servers? These questions get harder as the complexity of your application grows. Microservice based architectures and cloud-based dynamic infrastructures are technologies that help you keep your application running with high availability, even during times of extreme scaling. But real cloud success, at scale, requires much more than a basic lift-and-shift migrati...
David Friend is the co-founder and CEO of Wasabi, the hot cloud storage company that delivers fast, low-cost, and reliable cloud storage. Prior to Wasabi, David co-founded Carbonite, one of the world's leading cloud backup companies. A successful tech entrepreneur for more than 30 years, David got his start at ARP Instruments, a manufacturer of synthesizers for rock bands, where he worked with leading musicians of the day like Stevie Wonder, Pete Townsend of The Who, and Led Zeppelin. David has ...
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
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.
Addteq is a leader in providing business solutions to Enterprise clients. Addteq has been in the business for more than 10 years. Through the use of DevOps automation, Addteq strives on creating innovative solutions to solve business processes. Clients depend on Addteq to modernize the software delivery process by providing Atlassian solutions, create custom add-ons, conduct training, offer hosting, perform DevOps services, and provide overall support services.
Contino is a global technical consultancy that helps highly-regulated enterprises transform faster, modernizing their way of working through DevOps and cloud computing. They focus on building capability and assisting our clients to in-source strategic technology capability so they get to market quickly and build their own innovation engine.
When applications are hosted on servers, they produce immense quantities of logging data. Quality engineers should verify that apps are producing log data that is existent, correct, consumable, and complete. Otherwise, apps in production are not easily monitored, have issues that are difficult to detect, and cannot be corrected quickly. Tom Chavez presents the four steps that quality engineers should include in every test plan for apps that produce log output or other machine data. Learn the ste...
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...