Académique Documents
Professionnel Documents
Culture Documents
WHITE PAPER
Abstract
This whitepaper provides an introduction to creating C++ Web services and focuses on:
» An example showing step by step how to create and implement a C++ Web service
Introduction
This paper describes how to develop and host high performance C++ Web services, including using advanced
XML, SOAP, and WSDL productivity tools for transforming new and existing C++ applications for use in
Service Oriented Architectures (SOA).
The focus is on HydraExpress, part of the Rogue Wave® Hydra Suite, which also includes the HydraSDO™
data components that implement the Service Data Object (SDO) specification, and HydraSCA, the first product
available for deploying high-performance SOA applications based on the Service Component Architecture
(SCA) specification. The SDO and SCA specifications are multi-language industry SOA specifications available
in both Java and C++.
» Web services require foundation pieces not supplied by C++ platform/libraries, including critical protocol
implementations such as HTTP requests and responses.
» Since C++ is a “compile time” language it is difficult to map it with dynamic systems like Web services.
» C++ is a very high-performance language, but writing scalable, threaded infrastructure code can be very
complicated.
Often, new “message bus” middleware is purchased to address this challenge. Message bus products provide
a C++ API and may require significant changes to the existing application. The middleware then uses costly
“bridges” to communicate with the rest of the enterprise, thereby providing access to the C++ application. The
Code generation technology provides a customized, service-specific programmatic interface built upon a robust
framework for communicating with other processes. The high-level interface generated by HydraExpress
interacts with the underlying framework, which in turn handles the details of various networking, XML, and
Web Services standards. This approach separates the business logic code from the underlying communication
framework, ensuring long-term flexibility and compatibility.
Web services fabrication products like HydraExpress support the SOA approach by making it easy to create
Web services from both new and existing business processes. Once exposed through a Web service, these
processes can interact with other WebsServices anywhere on the network, regardless of the technology that
underlies these services.
Message formats in HydraExpress are based on the SOAP protocol, a widely accepted, easy-to-use mechanism
for transferring messages over a network. As shown below, to use HydraExpress, developers supply a standard
Web Services Description Language (WSDL) file. HydraExpress automatically generates a skeleton service that
handles the details of protocols, standards and networking to ensure interoperability. Developers then drop in
new or existing C++ business logic to create a ready-to-deploy service that can be used in many types of SOA
applications.
SOA Application
HydraSCA
OYS TO
s s C++ DEP
L
SOA Application
Custom or 3rd
party
» Efficient evolution. The modular design of HydraExpress enables you to quickly adapt the application as
your business needs change, allowing you to modify only the areas that require adjustment.
» Faster time-to-market. HydraExpress improves developer productivity so you can deliver effective
service-oriented applications on schedule and on budget.
» Cost savings. With HydraExpress, you can achieve the flexibility of service-oriented applications while
leveraging your existing investments where it makes sense, drastically reducing the need to rewrite, test
and optimize proven application logic.
HydraExpress features:
» A robust container for hosting C++ Web Services and Servlet servers
» Automatic generation of C++ server skeletons built to run inside the HydraExpress container
The basic steps involved in creating and deploying a C++ Web service and client are as follows:
The WSDL file used in the example describes a Greeting Service that has a single operation (sayHello) which
takes a string as input and returns a string as output. The WSDL file can be found in the HelloWorld tutorial that
is available with the HydraExpress evaluation.
i. Ensure that your C++ compiler is set up in your environment and available in the PATH
environment variable
iii. On UNIX/Linux set the RWSF_HOME environment variable to the HydraExpress root directory
iv. Run the script rwsfvars located in the HydraExpress root directory
Further information on configuring the environment is available in Section 2.3 of the HydraExpress User’s
Guide which is provided with the HydraExpress evaluation.
i. Using a command prompt setup as described above, invoke rwsfgen passing it the name of the
project to be created and the WSDL file name:
Alternatively you can save the project settings in an xml project file, and pass this as the sole argument to
rwsfgen. A sample project file is provided with the HelloWorld tutorial.
Figure2
Edit the sayHello method so that it returns “Hello” + the string passed from the client.
std::string
GreetingPortTypeImp::sayHello(rwsf::CallInfo& callInfo, const std::string& hellorequest_in)
{
return std::string(“Hello “ + hellorequest_in);
}
Edit the invoke_sayHello method so that it calls the proxy’s sayHello method with a fixed input string of
“World !”
void invoke_sayHello(GreetingBindingProxy& proxy)
{
std::string hellorequest_in(“World!”);
std::string return_ret;
rwsf::CallInfo callInfo;
try {
return_ret = proxy.sayHello(callInfo, hellorequest_in);
std::cout << “Server Response: “ << return_ret << std::endl;
} catch(const rwsf::SoapFaultException& e) {
std::cout << “Fault Code: “ << e.getFault().getFaultcode().asString() <<
std::endl;
std::cout << “Fault String: “ << e.getFault().getFaultstring() << std::endl;
}
}
Change to the HelloWorldExample directory and run nmake (Windows) or make (Unix/Linux) at the
command prompt. This builds the HelloWorld client and service.
Run nmake deploy (Windows) or make deploy (Unix/Linux) to deploy the service.
Figure3
A new command window appears showing the helloworld service has been loaded and is running (Loading
context: /helloworld/)
Figure 4
Figure 5
Support for message patterns. HydraExpress supports the four basic message patterns defined in the WSDL
specification: request-response, the pattern most often used by Web services, one-way, notification, and solicit-
response. The message patterns can be combined to create anything from applications based on well-defined
models such as publish/subscribe to arbitrarily complex, choreographed SOA applications.
Support for sessions and other state-dependent processes. HydraExpress has built-in support for session
management. In addition, the generalized support for metadata in headers can be adapted to support sessions,
transactions, and other processes that depend on state.
Support for XML binding. The HydraExpress code generator automatically compiles XML Schemas into C++
datatypes, whether the schema is embedded in the WSDL file, or the WSDL references an outside schema.
Support for SOAP attachments. HydraExpress creates code to support MIME bindings that are defined in
WSDL.
Support for WSDL-defined faults. HydraExpress generates classes that encapsulate fault messages defined in
the WSDL, and server code for capturing and returning fault messages to the client.
An HTTPS transport. Accessible from the command line or built into the client, this transport provides for a
secure client that uses HTTPS.
Generated documentation. The code generator creates full, detailed documentation for all generated datatypes.
The key elements of the SCA specification offer the possibility of creating composite SOA applications using
reusable SOA components in any technology:
» Decoupling of application logic from the details of its invoked service calls
» Multiple language support, including C++ and Java, as well as related programming standards such as
BPEL, XLST
» Binding services via SOAP-based Web Services, EJB, JMS, JCA, RMI, and more
» Data defined via Service Data Objects (SDO). The SDO API is available in both C++ and Java
Summary
This paper details the benefits of C++ Web Services development and takes the reader step by step through a
simple example. It also highlights the challenges faced when developing Web Services in C++ generally and
illustrates how developers can save considerable development time and effort, while producing code that is
robust and easily maintainable. Lastly, some advanced C++ Web Services features are discussed.
USA 1-800-487-3217 FRANCE +33 (0)1 30 09 78 78 GERMANY +49 (0)6103 59340 UK +44 (0)118 9360710
www.roguewave.com
Copyright © 2008, Rogue Wave Software, Inc. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. All other
trademarks are the property of their respective owners.