Point of Sales use case study with WSO2 Web Services Framework for C++

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Nandika Jayawardana
  • 24 Nov, 2009

Nandika Jayawardana explores how a C/C++ based Web services stack can be used to add the much needed flexibility and integration capabilities to a legacy point of sales system.

Contents
  1. Introduction to WSO2 Web Services Framework for C++
  2. Why use WSO2 Web Services Framework for C++
  3. A point of sales use case scenario
  4. Scenario implementation with WSO2 Web Services Framework for C++
  5. Summary

1. Introduction to WSO2 Web Services Framework for C++

WSO2 Web Services Framework for C++ (WSO2 WSF/C++) is a C++ Web Services API built on top of the popular
WSO2 Web Services Framework for C. It has support for many WS* specifications including WS-Security,
WS-Policy, WS-Addressing, WS-Reliable Messaging and WS-Eventing in addition to the
basic Web services capabilities.WSO2 Web Services Framework for C++ provides a comprehensive C++ API covering most of the available features from WSO2 Web Services Framework for C. WSO2 Web Services Framework for C++ comes with inbuilt code generation tool which provides a comprehensive XML data binding solution. WSO2 Web Services Framework for C++ has the widest range of WS* coverage among C++ Web services stacks available today.

2. Why use WSO2 Web Services Framework for C++

When selecting a C/C++ Web service stack for a Web services solution, there are multiple factors that should be considered. These include the portability, interoperability, support for security, tooling for rapid development available from the Web services stack. WSO2 Web Services Framework for C++ fulfills all of these requirements and has more.

1. Portability:

'Portability is the ability to run on multiple operating systems without having to make any changes to the code base'. Since WSO2 Web Services Framework for C++ is built on top of the WSO2 Web Services Framework for C library, which is designed with a platform abstraction layer, it can run on multiple software platforms including Windows XP, Windows Vista, Linux, Solaris and MacOS, without any change.

2. Interoperability:

Interoperability is the ability of diverse systems to work together. WSO2 Web Services Framework for C++ is interoperable with major Web services stacks like .Net, Apache Axis2 Java and WSO2 Web Services Application Server (WSO2 WSAS).

3. Security:

When dealing with important and critical information, it is essential
to secure that information so that the confidentiality and integrity of the exchanged
information is preserved. WSO2 Web Services Framework for C++ supports both transport level security (SSL/HTTPS) and message level security (WS-Security). Therefore, when using WSO2 Web Services Framework for C++ for your Web service implementations, whenever the need arises, you can easily utilize the security
capabilities provided by WSO2 Web Services Framework for C++ to secure your Web services.

4. Code Generation tools:

When implementing Web services, it is always necessary to have the tools to generate code by pointing to a WSDL contract. This way, developers are quickly able to develop working code without having to learn all the complex details of WSDL and XML-Schema.

5. Multiple deployment options:

WSO2 Web Services Framework for C++ can be deployed with either Apache 2.0 or Internet Information Services (IIS).

3. Point of sales use case scenario

 Point of sales (POS) or checkout is both a checkout counter in a shop, and the location
where a transaction occurs
(Wikipedia). POS system consists
of both hardware and software and records sales as it happens. POS
technology is widely used in retail locations such as super markets, restaurants and
stores. When a customer wants to buy an item or pay a bill, the point of sales
system is extremely useful to quickly record the details such as date, time, amount and issue
a bill and keep track of the inventory and the cash. Often in stores, these systems
also include other hardware such as scanners, bar code readers, in addition
to the monitor and the printer.

In this use case scenario, we are considering a large retail store chain. The retail store chain
has been using a POS system for a number of years and it is functioning pretty well.
However, the management is interested in streamlining the entire operations of the
store chain by connecting all systems together and automating as much functionality
as possible. The management would like to monitor the customer buying patterns and
store sales performance and analyze market trends remotely. The management expectations are the ability to provide many new services from the POS terminals and from its e-commerce web site and being able to quickly launch new products and promotions. Also it is required to automate functionality such as placing orders for the items that are in short supply in the store. The store chain wants to reuse much of its existing software infrastructure which is based on C/C++.

The current software system consists of each retail store having a backend processing server
and a set of POS terminals.

The POS system designed with Web services

This existing system can be converted to a Web service based on a distributed system catering for all of the above described requirements. Due to the loose coupling and interoperability achieved using Web services,
it is guaranteed that the retail store chain's POS applications can be integrated with the retail
stores chain's other applications. Another great advantage of Web services is the ability
to wrap existing applications and provide service interfaces which makes functionality
easily accessible to many other applications. This would provide accessibility to many
of the backend system information and data which was not accessible from outside the system.

The loosely coupled connectivity gained by Web services
allows the ability to communicate with other systems and gives the flexibility to change the system functionality as and when required.

Let’s look at how some of the above scenarios can be realized with Web services:

1. Monitoring the customer buying patterns and store sales performance remotely

All the store sales transaction details are recorded by the POS
system. The requirement is to access this data remotely and process that information.
This requirement can be achieved by building Web services that would expose the necessary data as a Web service available from each store of the retail chain. Then an application can be built to use these Web services to analyze the data.

2. Placing orders automatically for items that are in short supply in the store

The retail store chain would have it's own warehouses where the inventory is stored. Each store can request the inventory when required. This entire process can be automated by implementing Web services. The warehouse can host a Web service allowing the orders to be placed for the inventory. Since the POS system keeps the sales and the inventory in a given store,when a stock of a given item is being reduced,this Web service can be invoked automatically by the POS system to place an order.

By exposing the Point of sales (POS) backend system functionality as a well designed set
of Web services will help the retail store to inter-connect their systems together
and also inter-connect with its e-commerce web site. This will allow monitoring applications to be built using these services to analyze customer buying patterns, sales trends of the stores and market trends. It will also allow accommodating new functionality to the system without having to change other components
of the system which will help providing new services, new promotions though both POS terminals as well as the retail store web site.

4. Scenario implementation with WSO2 Web Services Framework for C++

There are two basic scenarios that should be considered for our implementation:


Exposing an Application functionality as Services.

The first step is to finding out what functionality should be made available to the outside
world as Web service operations and compose them as services. Then the designed services
can be quickly implemented using WSO2 Web Services Framework for C++ as a Web services stack. In the service, the service operations invokes API calls to the application to expose application functionality through Web service operations.


Client invoking a Web service to send and receive information.
In this scenario, the client would invoke a service endpoint to send and receive
information. The client is communicating with the Web service using SOAP messages
and the Web service client will be embedded within the C++ application.

   
Let’s look at how to use WSO2 Web Services Framework for C++ to build Web services for the
above discussed scenarios. As stated previously, a store's software system consists of a backend server
which does the processing of the data received through the POS terminals, handles
all the business logic and sends back the results to the POS terminals. The backend
server functionality should be broken into many services and hosted as Web services. The
POS terminal's software system should also include Web service clients.
 
Here is a very high level diagram depicting how the communications will happen in
this scenario. 
At a POS terminal, a Web services client communicates with the backend Web services
to process information and handles transactions happening from the POS terminal.
At the backend, the backend server exposes a number of Web services which are invoked
by the POS terminal in order to handle the transactions. In addition, the transaction
data can be sent to other Web services which will process that information to calculate
the existing inventory of the store and what products need to be ordered. 
 
The following use case diagram depicts a high level deployment
scenario for the Services implemented using WSO2 Web Services Framework for C++. 
 
 
As demonstrated in the diagram, the backend server application functionality is
exposed as a number of Web services with WSO2 Web Services Framework for C++. WSO2 Web Services Framework for C++ itself is deployed as an extension to a Web server which allows high performance and scalability. Currently WSO2 Web Services Framework for C++ supports deploying as a Web server extension for both IIS and Apache 2.0 Web servers.
 
The POS terminal application will be using the client to invoke the services hosted
by the back end server. In addition it could also be communicating with many other
Web services hosted at other stores of the enterprise. A service can also be communicating
with other services. These communications can be streamlined by deploying an Enterprise Service Bus (ESB)
at each store.

Implementation of services with WSO2 Web Services Framework for C++
Once the design of the Web services is finalized, there are two approaches to building
services:
 
1. Code first approach (Start with code)
2. Contract first approach (Start with a WSDL and build services)
 

If you have designed the WSDLs for the services, the services can be implemented very quickly by using code generation. WSO2 Web Services Framework for C++ comes with a code generation tool which allows you to generate client stubs and services skeletons by pointing to a WSDL. Once you have the generated service skeletons, which handles all the complexities of XML serialization and deserializaton, the developer only
needs to fill out the business logic.

The generated service skeletons contains the methods corresponding
to each of the operations defined in the WSDL. The actual application, which needs
to be exposed as a service should be invoked through the API calls within the method of
implementation.

The service implementation should be build as a shared library in WSO2 Web Services Framework for C++ deployment model. The service shared library (either a ‘.so’ or a ‘.dll’) should be copied to a folder with the same name as service name along with the automatically generated service description XML named services.xml. This service folder is again copied to the services folder under WSO2 Web Services Framework for C++ repository. Please refer to the WSO2 Web Services Framework for C++ documentation to further understand the concept of service repository.

If the code first approach is followed, you should extend from the ServiceSkeleton base class and implement the abstract methods invoke, onFault and init. The class methods corresponding to the operations defined in the service can be selectively invoked within the invoke method by using any of the dispatching
techniques. The deployment is same as described above.

For hosting, WSO2 Web Services Framework for C++ framework can be interconnected with a Web server such as IIS or Apache 2.0. The maximum performance can be archived by deploying as either IIS/Apache 2.0 module.


Consuming Web services with WSO2 Web Services Framework for C++

The WSO2 Web Services Framework for C++ client API primarily consists of methods defined in classes ServiceClient and Options. The ServiceClient class provides different service invocation methods
such as receive (Request-Response) vs send (Request Only). The Options class is
used to configure the instantiated service client object. With a few lines of code
a client can be implemented. If the WSDL for the service is available, a client
can be code generated and implemented.

 

5. Summary

WSO2 Web Services Framework for C++ is a complete Web services stack. It has the support for basic Web services standards, handles binary attachments and also has the widest coverage of WS*
standards including WS-Addressing, WS-Security, WS-Security Policy, WS-Secure Conversation,
and WS-Reliable Messaging. The WSO2 Web Services Framework for C++ provides a comprehensive service and client APIs for the C++ developer. WSO2 Web Services Framework for C++ comes with built-in code generation tool to support rapid development of services and clients.

WSO2 Web Services Framework for C++ can be used to wrap existing applications and expose
them as a Web service as well as to enable new applications developed in C/C++ to
talk to other heterogeneous systems.

In this article, we explored the usage of WSO2 Web Services Framework for C++ in converting a software system in a retail store to a loosely coupled Web services based system integrating it with it's other stores providing value to the retail store chain.

Author

Nandika Jayawardana, Technical lead, WSO2 Inc. nandika at wso2 dot com

About Author

  • Nandika Jayawardana
  • Software Developer
  • WSO2