Part I of this series set out to address the shortage of information on C++ and Web services, showing readers how to create a C++ Web service client. Part II continues the mission by describing how to author an actual Web service, using SOAP, C++, and a little Java.
by Peter Lacey
Jan 15, 2003
Page 2 of 4
Generating the WSDL Document
One of the tricks to creating a Web service is deciding where to start. There are two principal components to a Web service: the service itself and the WSDL document that describes it. It is helpful to have the WSDL in hand when developing a service, as you can then use the WASP wsdlc utility to auto-generate the client stubs and service skeletons. Conversely, since WSDL documents are a bit complicated, it would also be nice not to have to create the WSDL manually.
Fortunately, there is a solution to this problem. While the WASP for C++ product does not have a means of generating a WSDL from a C or C++ source or object file, it is possible to generate a WSDL from a Java class file. This is why you installed the Companion Tools. It contains, among other things, the Java2WSDL utility.
The first thing you want to do is create an extremely simple Java interface for your service. As noted, this service will consist of two operations for converting back and forth between Fahrenheit and Celsius. Call them ftoc() and ctof(). Each should take a single floating point number as an argument and return a floating point number as a response. Decide now that the endpoint for this service (that is, its URI) will be /tempconverterservice/. Knowing this, you can move on to writing your Java interface.
Save this source as Tempconverter.java and compile it.
$ javac Tempconverter.java
This generates a class file that you can use to create the WSDL document. To do this, call the Java2WSDL.sh utility bundled with WASP for Java, and supply a few flags. The following command has been formatted for readability:
--service-mapping Tempconverter=Tempconverter: Causes the WSDL <service> name attribute to be set to the string on the right for the Java class named on the left, instead of using the default name "JavaService."
--class-mapping Tempconverter=http://localhost:6070/tempconverterservice: Causes the WSDL service/port/address element for the class on the left to be set to the URI on the right. In this case, port 6070 is the default HTTP port for WASP for C++. tempconverterservice is the arbitrary name decided on earlier for this particular service (I'll refer to it again later).
--no-java-mapping-extension: Removes from the WSDL special constructs for handling overloaded methods in Java.
--sbs rpc: Sets the SOAP binding style to "rpc", instead of "document."
--ses encoded: Sets the SOAP encoding style to be "SOAP encoded" instead of "literal."
By default, Java2WSDL creates a file called Definitions.wsdl. For consistency's sake, rename this file to Tempconverter.wsdl.