CXF SOAP (JAX-WS) Webservice Wrapped Style

In this tutorial, we will take the WSDL created here and change it to a wrapped style web service.

Example Scenario:

In the example Quick Overview of SOAP (JAX-WS) webservice with CXF, we built a web service from WSDL and the parameter style is called BARE. The method of the interface takes a request object and returns a response object. The one we are going to build here is called WRAPPED style. It means that each parameter of WSDL message is placed into the message body as a child of message root, which is the operation name. In RPC style of web service call, this is default. Let’s tweak the created WSDL a little bit to make it wrapped style. The web service would take two binary inputs and provide the sum in response.

Project artifacts:

Technologies used –

a. Eclipse IDE for Java EE developer (Mars)
b. Preinstalled Maven with Eclipse Mars
c. Tomcat 7.0.64
d. CXF 3.0.3
e. Java 1.8

Jars used –


Before we begin:

To learn how to create maven web project, please read this tutorial.

To learn how to create a WSDL, please read this tutorial.

– The  modified WSDL

If noticed carefully, in wrapped style development of web service, the operation name, the message part name and the element name are all same.

The element name of the response in created by appending “Response” to the request element name.

<wsdl:definitions xmlns:soap="" xmlns:tns="" xmlns:wsdl="" xmlns:xsd="" name="BinaryAdditionService" targetNamespace="">
        <xsd:schema targetNamespace="">
            <xsd:element name="binaryAddWrapped">
                        <xsd:element name="a" type="xsd:string"></xsd:element>
                        <xsd:element name="b" type="xsd:string"></xsd:element>
            <xsd:element name="binaryAddWrappedResponse">
                        <xsd:element name="out" type="xsd:string"></xsd:element>
    <wsdl:message name="binaryAddRequest">
        <wsdl:part element="tns:binaryAddWrapped" name="parameters"></wsdl:part>
    <wsdl:message name="binaryAddResponse">
        <wsdl:part element="tns:binaryAddWrappedResponse" name="parameters"></wsdl:part>
    <wsdl:portType name="BinaryAdditionService">
        <wsdl:operation name="binaryAddWrapped">
            <wsdl:input message="tns:binaryAddRequest"></wsdl:input>
            <wsdl:output message="tns:binaryAddResponse"></wsdl:output>
    <wsdl:binding name="BinaryAdditionServiceSOAP" type="tns:BinaryAdditionService">
        <soap:binding style="document" transport=""></soap:binding>
        <wsdl:operation name="binaryAddWrapped">
            <soap:operation soapAction=""></soap:operation>
                <soap:body use="literal"></soap:body>
                <soap:body use="literal"></soap:body>
    <wsdl:service name="BinaryAdditionService">
        <wsdl:port binding="tns:BinaryAdditionServiceSOAP" name="BinaryAdditionServiceSOAP">
            <soap:address location=""></soap:address>


– The initial project directory structure 

WrappedStyleDire Struct

– pom.xml ( at the beginning)

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
    <name>QuickSOAPWrappedStyle Maven Webapp</name>
            <name>Apache SNAPSHOT Repository</name>
            <!-- the plugin that converts the wsdl to java source code -->
                                    <!-- wsdl location to be used for building java classes. -->
                                    <!-- wsdl location for run time -->
                                        <!-- we need server side implementation java classes -->


Please run maven clean and install.

You should see java classes being created. Comment the plugins tag in pom.xml so that when we build the war file, the java classes shouldn’t be recreated and our changes are not overridden.

Let’s proceed…

  1. Final project directory structure

Wrapped Final Directory Struc

– WSDL and class mapping

The following image depicts the mapping based on which CXF tool wsdl2java and JAXB created the classes from WSDL and schema.

WSDLClassMappingWrapped : It contains the mapping between target namespace of the WSDL ( and the created package name (com.javanbeyond.binaryadditionservice).It can be modified by passing -p argument to wsdl2java tool of CXF. Each package has one : It acts as a factory class to create objects for the classes in its package. If there are multiple namespaces in schema, so will be multiple packages and each package has its own ObjectFactory class. : The Request class which acts as a wrapper for the incoming request and into which the incoming payload is unmarshalled to. : The Response class which acts as a wrapper for the outgoing response from operation method and which is marshalled to response XML. : The web service interface created based on port type in WSDL. : The implementation class of BinaryAdditionService interface. All our business logic will be written here or will start here. : The client representation of the Service.

2. Implementation class

file : BinaryAdditionServiceSOAPImpl. This class has a method created from WSDL operation and all our business logic should be in this method or should start from this method. If you look closely, the method parameters and return types are different from BARE style. It takes two String and returns one, instead of a request and response object. At the time of unmarshalling, the parameters are extracted from the request object and passed as arguments to the operation method. At the time of marshalling, the returning parameter is wrapped inside the response object.


 * Please modify this class to meet your needs
 * This class is not complete

package com.javanbeyond.binaryadditionservice;

import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;

 * This class was generated by Apache CXF 3.0.3 2015-09-25T22:40:17.940-05:00
 * Generated source version: 3.0.3

@javax.jws.WebService(serviceName = "BinaryAdditionService", portName = "BinaryAdditionServiceSOAP", targetNamespace = "", wsdlLocation = "classpath:BinaryAdditionServiceWrapped.wsdl", endpointInterface = "com.javanbeyond.binaryadditionservice.BinaryAdditionService")

public class BinaryAdditionServiceSOAPImpl implements BinaryAdditionService {

    private static final Logger LOG = Logger

     * (non-Javadoc)
     * @see com.javanbeyond.binaryadditionservice.BinaryAdditionService#
     * binaryAddWrapped(java.lang.String a ,)java.lang.String b )*
    // in Wrapped style , instead of receiving request object, we are receiving
    // the parts of the request
    public java.lang.String binaryAddWrapped(java.lang.String a,
            java.lang.String b) {"Executing operation binaryAddWrapped");
        try {
            java.lang.String _return = Integer.toBinaryString(
                    Integer.parseInt(a, 2+ Integer.parseInt(b, 2));
            // We don't have to return the response object. Just the part is
            // enough
            return _return;
        catch (java.lang.Exception ex) {
            throw new RuntimeException(ex);



3. Spring configuration.

file : BinaryAdditionWrappedConfig.xml. Spring application context file to bind different instances of classes (beans) in spring container including our web service class within an application.


<beans xmlns="" xmlns:xsi="" xmlns:jaxws="" xsi:schemaLocation="">
    <!-- The actual implementation class and the corresponding url to access         it . Check how a simple bean is exposed as web service in cxf -->
    <jaxws:endpoint id="calculateEndpoint" implementor="#binaryCalculate" address="/WrappedBinaryCalculatorService"></jaxws:endpoint>
    <bean id="binaryCalculate" class="com.javanbeyond.binaryadditionservice.BinaryAdditionServiceSOAPImpl"></bean>


4. Deployment descriptor

file: web.xml. Deployment descriptor file for mapping URIs to CXF servlet. The spring configuration file location is added as a context parameter through web.xml.


<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "" >
    <display-name>Archetype Created Web Application</display-name>

Example Execution:

  1. Please run maven clean and install and deploy the war file created in Tomcat . You can use your own choice of SOAP client. In this tutorial, we will use SOAPUI, a popular web service client.
  2. Open SOAPUI and create a SOAP project with the url “http://localhost:8080/QuickSOAPWrappedStyle/soap/WrappedBinaryCalculatorService?wsdl”

SOAP Project CXF WrappedStyle

3. Press OK. A SOAP project should get created.

SOAPUI Project Wrapped Style

4. Fill any binary input and press the send button. You should get the sum as response .

Wrapped SOAP UI Request Response



Back to Top