26
Thu, Dec
0 New Articles

XML Part 3: Code Development

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Well, here we are at the third and final article in this series. In the first article, I talked about XML in general and explained the components that make up an XML document. I placed a heavy emphasis on the fact that XML is really a definition of tag semantics, not a definition of tags, like HTML. The tags you use and what you populate the tags with is up to you. As long as you follow the rigidity of XML, you'll be fine. The last sections of the first article dealt with reading, manipulating, validating, and transforming XML.

The second article discussed bringing XML to the next level, which is application-to-application (A2A), with Web Services being the enabler in this paradigm. While many XML standards provide security, message delivery, service advertisement, and subscription, there is no part of XML that actually does these things. And if you already have functionality such as encryption, why not just snap that into your XML infrastructure?

In this article, I'm going to get a little less scholastic and a little more hands-on. I'll show you a pseudo system and some of the code that could be used to support this system when it communicates with other systems. A good friend of mine, Steve Bos, who I have worked with for years, is an excellent programmer and has created the code in this article. He has several years of hands-on experience with XML, utilizing many of the technologies already discussed.

It's All in the Design

Let's start with a simple system. We are going to be reviewing a hotel reservation portal. There are three external entities: the customer, the hotel, and the credit card authorization firm. The portal provides a nice interface for what can be a batch and/or interactive system. Its all in the design!

The hotel may send pricing information to the portal either at a fixed interval (such as nightly or weekly) or when there are price changes. Availability information may also be sent in batch, or the portal can interactively query the hotel to see if there are rooms available when a user makes a request. While we will not code every possibility, it is important to look at different possibilities in the hopes that you come with some XML ideas on your own.

Tools Transform the Design

In the code examples that follow, Steve used Micosoft's C# (pronounced "C sharp") because of the vast array of utilities Microsoft has made available to quickly build XML/Web Service applications. Universal Description, Discovery, and Integration (UDDI) and Web Services Description Language (WSDL) definitions are created with the click of a button, which takes the complexity out of these services. Simple Object Access Protocol (SOAP) messages complement UDDI and WSDL by connecting to remote Web Services. I'll show you what a SOAP message should look like.

SOAP Message

Let's take a look at a SOAP message. (The text was formatted for readability. If this were real XML, you would not see any tabs or carriage returns/line feeds.) This SOAP message sends a request to the hotel on behalf of the user. It includes the hotel ID, client name, room options, and some payment information.


http://www.w3.org/2001/XMLSchema-instance" 

xmlns:xsd="http://www.w3.org/2001/XMLSchema

xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  
    
      2015432
      Mr. Wilson
      Honeymoon Suite
      2003-11-26
      2003-11-28
      Standard
      MC
      0000-0000000
      99/12
      Mr. Bud Wilson
    
  

Figure 1: This sample SOAP message requests hotel availability information.

Let's examine this code.

The standard first line indicates that we are using XML Version 1.0 and that the text encoding is UTF-8.

The next few lines set up some "run-time" properties of the document. A nice thing about XML is that you can follow the convention of anyone on the Internet in terms of naming your XML data elements. For our SOAP envelope, we will be using the standards from the Universal Resource Indicator (URI) http://www.w3.org/2001/XMLSchema-instance (name space xmlns). We will also be using the XML Schema Definition (xsd) from http://www.w3.org/2001/XMLSchema and the SOAP definition from http://schemas.xmlsoap.org/soap/envelope/.

The SOAP payload begins with . The next line opens an Execute tag that includes a URI as a parameter. This is the location of the remote system (in our case, the hotel we will be booking our reservation with). The remainder of the SOAP message contains the parameters that will be passed to the hotel, such as guest name, credit card information, etc.

As with other XML standards we reviewed, all elements must be closed out. The last three lines of the SOAP message close out the Execute, SOAP:Body, and SOAP:Envelope elements.

The intended recipient of a SOAP message is a Web Service, which supplements a Web server. When a new SOAP message comes in, the Web Service automatically parses through the message and sends the parameters to an object that has the business logic programmed into it. This object could update database tables, check availability of a room, call out to external credit card authorization companies, or anything else that is programmatically possible. In our example, we are going to check the availability of the room and then confirm that the funds are available on the credit card. Once this is complete, we will return the following XML to the program that initially submitted the XML, which is waiting for a response.

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 454


http://www.w3.org/2001/XMLSchema-instance" 

xmlns:xsd="http://www.w3.org/2001/XMLSchema

xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  
    
      TRUE
    
  

Figure 2: This SOAP message is a response to the original request.

This response looks a little different from the request because we included the HTTP headers. HTTP/1.1 200 OK indicates that the document you were posting to was found and that the operation completed successfully. An HTTP/1.1 404 File Not Found would indicate that the Web Service you are trying to publish was not found. You would see this message if you went to a URL and the document you entered was not found on the server. The remaining lines of the HTTP headers indicate the text encoding type, which matches the UTF-8 that we had in our request, and the length of the response.

We start the XML portion the same way we started the request. The XML version and encoding format is indicated. The SOAP envelope element is opened with references made to the same URIs as the request.

The SOAP body element is opened as well, and it uses an interesting parameter. The ExecuteResponse element has the same URI as the Execute element in the request. This is because the same Web Service that is accepting the request is then creating the response.

WSDL

First and foremost, WSDL defines a Web Service. In order to define this Web Service, it needs to describe the "binding," or what type of message to send and where (remember, a Web Service can operate from email). It also defines the port and the message that will traverse the port. A message is a series of parameters to be either received or sent, and the WSDL defines the specific parameters in a message and the format of those parameters.

This sounds both somewhat difficult and easy at the same time. You can see the hierarchy from the definition I provided above, but coming up with the syntax may be tedious. This is why you would almost never define WSDL yourself. Many packages, including C#, provide the run-time engines that create the WSDL for you. Let's look at an example that would define the reservation service that our SOAP message would be sent to.


http://schemas.xmlsoap.org/wsdl/http/" 

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/

xmlns:s="http://www.w3.org/2001/XMLSchema

xmlns:s0="http://192.168.1.1/ReservationPortal/

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/

xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/

xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/

targetNamespace="http://192.168.1.1/ReservationPortal/

xmlns="http://schemas.xmlsoap.org/wsdl/">
  
    

targetNamespace="http://192.168.1.1/ReservationPortal/">
      
        
          
    
            
            
            
            
            
            
            
            
            
          
        
      
      
        
          
            

type="s:string" />
          
        
      
      
    
  
  
    
  
  
    
  
  
    
      
      
    
  
  
    
    
      http://192.168.1.1/ReservationPortal/ReserveRoom" 

style="document" />
      
        
      
      
        
      
    
  
  
    
      
    
  

Figure 3: This code defines the reservation service that our SOAP message is sent to.

As in our SOAP requests, the first section relates to the version of XML we are using and the encoding method. We then reference external naming schemas, including one of our own located at http://192.168.1.1/ReservationPortal/.

In WSDL, the subcomponents are defined first and the Web Service itself is defined last. The first definition is a schema. The first schema we define is ReserveRoom, a series of variables required to reserve a room. Look back at the SOAP example, and you'll see that the variable names are slightly different, but the schema definition matches what we are sending via our SOAP request.

The minOccurs and maxOccurs tags in the schema allow you to define how many times an element is present. Setting both of these values to "1" mandates that this variable be present only once. We could complicate this WSDL by adding a GuestNames tag that could have one to 100 names, depending upon the size of the room. So your minOccurs would be "1" and your maxOccurs would be up to "100."

In this WSDL, we define a schema for both the input and the output. This allows us to "code it once, call it twice" as my COBOL instructor used to say.

Moving on down the example, we find the Message element, a simple element that indicates we are using the ReserveRoom schema for our ReserveRoomSoapIn message and the ReserveRoomResponse schema for our ReserveRoomSoapOut message. So now we have bound a schema to a message, but we're not done yet.

The next step in the WSDL is defining the ports that may be available for a Web Service. A complex Web Service would have many different ports. In our simple example, we kept the port to simply reserving a room, or ReserveRoom. As you can see from the example, the input message (SOAP in our case, as opposed to email) expects ReserveRoomSoapIn, and we will be outputting ReserveRoomSoapOut. You should recognize both of these from when we defined them as messages.

The binding area is complicated, as it defines what we expect and the order in which we expect it. Because you can have several SOAP messages that constitute a Web Service transaction, the binding indicates when and how to expect those message and in what format. It also describes what you should expect to be returned, which is important if there are several messages being sent to you.

Finally, we define the Web Service itself, including the address, and reference the binding that we just defined. I don't think there is any question as to why you would want an application to automatically generate the WSDL.

UDDI

As explained in the last article, UDDI provides a searchable directory of companies that upload their business classification information. UDDI encompasses uploading the information as well as searching it.

We're going to step away from the hotel reservation and perform a simple query that looks for information on Microsoft. Here's the code:

UddiConnection CONNECTION = new UddiConnection      (http://test.uddi.microsoft.com/inquire);
FindBusiness BUSINESS = new FindBusiness("Microsoft");
BUSINESS.FindQualifiers.Add(FindQualifier.CaseSensitiveMatch);
BUSINESS.CategoryBag.Add(CommonCanonical.NtisGovNaics1997,"51121","NAICS: Software Publisher");
BusinessList BUSINESSLIST = fbBUSINESS Send(CONNECTION);

This code excerpt is from C#, and as you can see, it is relatively easy to comprehend. The first line defines a new UDDI connection to the Microsoft Test server, which is specified by the URL. The second line of code stipulates the search criteria that we are looking for. In this example, we are looking for a business named Microsoft. The third line allows us to stipulate a series of qualifiers. We want to ensure that our search is case-sensitive and does not find "microSOFT." The fourth line hones in on the business classification standard (NtisGovNaics1997) and stipulates that we are looking for a software publisher. The final line initiates the connection and retrieves the information into the BusinessList object for your use.

Relatively simple, isn't it? Of course, the devil is in the details and what you do with that information once you have it. In our example, we know the company name that we are looking for. But what if we don't, and we are looking for a type of business? How can we discern the good from the bad and the ugly? And will we even be able to do this when we search for Hotel and receive hundreds of results?

The Future of XML

There will be many degrees of XML acceptance. At present, I see the landscape of XML as a collection of islands linked by shallow narrows that anyone can walk across at will. At each island is a different XML technology that solves a different problem. How many islands you travel to depends upon your ambitions and your specific business problems.

On the fringe of these islands, a super island will be established that has bridges and a hefty admission fee. These will come to you in the form of frameworks or add-ons to your business applications. They'll carry a significant cost but will be all-encompassing. Instead of studying standards and downloading SDKs and toolkits, you'll be able to go to the super island, which will provide full XML integration with all the functionality that the standards define.

There will also be an isolated island of third-party vendors. They will operate the Web Services, perform the UDDI registration and searching, define the WSDL to use your Web Services, and transport the SOAP messages to complete complex transactions. Aside from transaction and subscription fees, the process will be relatively painless, and you'll never have to leave your island.

Nonetheless, you will most likely have to get your feet wet with XML. It is a mutating technology that seems to be touching everything that is front and center right now. You now have a better understanding of XML and the superfluous technologies that extend it so that, when the time comes, you do not drown.

Additional Resources

Since publishing the first article in this series, MC Press Online has exploded with excellent in-depth articles on XML and its surrounding technologies. In addition to these articles, author Steve Bos, whose code has been introduced here, has a full-length book in the works. Expect to see it available at the MC Press store around May. This book will provide more details on the technologies introduced here and apply them to the iSeries.

Chris Green is a Senior Network Support Specialist located in Toronto, Ontario, Canada. He has eight years experience focusing on the iSeries and networking technologies. Utilizing this experience, he has authored over 30 articles and several white papers and has co-authored an IBM Redbook entitled Securing Your AS/400 from Harm on the Internet. Most recently, he has achieved Security Essentials (GSEC) certification from the SANS Institute. For questions or comments, you can email him at This email address is being protected from spambots. You need JavaScript enabled to view it..

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: