Consume jax-ws webservice using wsdl in Mule Project

This tutorial shows how we can consume service when we are given a wsdl file. We have seen how to create webservice and consume webservice in Mule Project but earlier we have not consume webservice from wsdl file rather we had created new mule flow for consuming webservice.

Please go through the tutorial create jax-ws webservice before reading below.
Mule Studio 3.5.0
Mule 3.4.1
JDK 1.6
WSDL file
Maven 2.x
WSDL file

<definitions targetNamespace="" name="HelloImplService">
        <xsd:import namespace="" schemaLocation="http://localhost:8888/jax-ws-ssl/hello?xsd=1"/>
    <message name="sayHello">
        <part name="parameters" element="tns:sayHello"/>
    <message name="sayHelloResponse">
        <part name="parameters" element="tns:sayHelloResponse"/>
    <portType name="Hello">
        <operation name="sayHello">
            <input wsam:Action="" message="tns:sayHello"/>
            <output wsam:Action="" message="tns:sayHelloResponse"/>
    <binding name="HelloImplPortBinding" type="tns:Hello">
        <soap:binding transport="" style="document"/>
        <operation name="sayHello"><soap:operation soapAction=""/>
                <soap:body use="literal"/>
                <soap:body use="literal"/>
    <service name="HelloImplService">
        <port name="HelloImplPort" binding="tns:HelloImplPortBinding">
            <soap:address location="http://localhost:8888/jax-ws-ssl/hello"/>


Step1. First create a Mule project called jax-ws-external in Mule Studio. If you do not know how to create a project then you can find that in Mule related other tutorials.
Step 2. We need to generate the client or stub from the wsdl file before invoking the service. We may generate the clients using the maven plugin or we can also generate using wsimport command from cmd prompt in Windows System. I will generate client using command. So I run the below command in cmd prompt.
<project root directory> wsimport -keep -d src/main/java http://localhost:8888/jax-ws-ssl/hello?wsdl

Open the cmd prompt. Go to the project root directory in Mule workspace. Note the few things in the command:

wsimport – generate clients from wsdl
-keep – keep the generated source files otherwise you will see generated class files
-d src/main/java – diretory where the client java files will be generated
http://localhost:8888/jax-ws-ssl/hello?wsdl – wsdl location

Once the command gets executed you will see the below files are generated in the package – in.webtuts.service

Step 3. Create the mule flow file with the following configurations. You can also create the mule flow using the visual editor.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mulexml=""
    xmlns:http="" xmlns:tracking=""
    xmlns:cxf="" xmlns=""
    xmlns:spring="" version="EE-3.4.1"
    <flow name="jax-ws-external" doc:name="jax-ws-external">
        <http:inbound-endpoint exchange-pattern="request-response"
            host="localhost" port="8084" path="jax-ws-external/msg" doc:name="HTTP" />
        <cxf:jaxws-client operation="sayHello" doc:name="SOAP"
            enableMuleSoapHeaders="true" clientClass="in.webtuts.service.HelloImplService"
            port="HelloImplPort" />
        <http:outbound-endpoint address="http://localhost:8888/jax-ws-ssl/hello" />
        <object-to-string-transformer doc:name="Object to String" />

We have few things to mention here
HTTP endpoint which takes input from the user and gives response, hence exchange-pattern=“request-response”
host and port – where the server is running
path – is the requested input from the user
SOAP component used for consuming SOAP based webservices
operation – look at the wsdl file for operation name
enableMuleSoapHeaders – by default true
clientClass – need to pass the client class name because we are consuming the service
port – which port to listen to
address – need to pass the service full address or location

is used to render the correct format data. HTTP outbound endpoint sends payload in XML format and expects to receive response in XML as well. However, SOAP client unmarshals XML content and sends plain String (returned from sayHello method). So, let’s turn the content-type into text/plain in order to avoid browser rendering issues.

Step 4. Now run the application. If application successfully starts up then go to the browser and type url http://localhost:8084/jax-ws-external/msg

You will get the output – Hello, jax-ws-external/msg
You can also test the service in java main class as follows:

package in.webtuts.service.test;
import in.webtuts.service.Hello;
import in.webtuts.service.HelloImplService;
public class HelloClient {
    public static void main(String[] args) throws Exception {
        HelloImplService service = new HelloImplService();
        Hello hello = service.getHelloImplPort();

Thanks for your reading. Please do not forget to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *