that were shone when I got tempered!

How to send a SOAP Request using CXF JAX-WS

leave a comment »

1.Create a Maven Project


2. WSDL setups

Download the WSDL file and put to the resources folder (/src/main/resources/). You can use the wsdl URL also without downloading.
Sample WSDL :


3. pom.xml configuration

Properties :


Dependencies :


cxf-codegen-plugin configuration


You can use the WSDL URL also instead of ${basedir}/src/main/resources/stockquote.wsdl.

Comment this cxf-codegen-plugin configuration part after you generated the code.

4. Generate the wsdl2java code.

Run pom.xml with clean install goals. This will generate the source for the WSDL in the location mentioned in (eg:${basedir}/target/generated/src/main/java)

Copy and Paste the generated packages to src/main/java folder.


5. Develop the service

Find the Adddress
This is mentioned in wsdl:service/wsdl:port/soap:address@location. (eg:

Find the ServiceClass.
This is mentioned in the wsdl:service/wsdl:port/@name (eg: StockQuoteSoap)

eg :

<wsdl:service name="StockQuote">
	<wsdl:port name="StockQuoteSoap" binding="tns:StockQuoteSoap">
  		<soap:address location="" />

Create client using address and the ServiceClass

protected StockQuoteSoap createCXFClient() {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    return (StockQuoteSoap) factory.create();

Find the Operation (meethod name), Requeest parameter(s) and Response type using the wsdl

<wsdl:portType name="StockQuoteSoap">
	<wsdl:operation name="GetQuote">
	  <wsdl:documentation xmlns:wsdl="">Get Stock quote for a company Symbol</wsdl:documentation>
	  <wsdl:input message="tns:GetQuoteSoapIn" />
	  <wsdl:output message="tns:GetQuoteSoapOut" />

<wsdl:message name="GetQuoteSoapIn">
	<wsdl:part name="parameters" element="tns:GetQuote" />

<wsdl:message name="GetQuoteSoapOut">
	<wsdl:part name="parameters" element="tns:GetQuoteResponse" />
  • Method name : wsdl:portType/wsdl:operation/@name relevanet to the wsdl:service/wsdl:port/@binding
  • Requeest Parameter(s) : wsdl:message/wsdl:part/@element relevant to wsdl:portType/wsdl:operation/wsdl:input@name
  • Response Type : wsdl:message/wsdl:part/@element relevant to wsdl:portType/wsdl:operation/wsdl:output@name

Invoke the operation (method) using the created client

private void invokeJaxWs() {
	StockQuoteSoap client = createCXFClient();
	String response = client.getQuote("test123");


GIT URL : <demo-cxf-jax-ws.git>


Written by Namal Fernando

August 2, 2016 at 7:32 am

Posted in JAX-WS, WebServices

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Ruth's Reflections

Contemplations from quakey quirky Christchurch

TED Blog

The TED Blog shares interesting news about TED, TED Talks video, the TED Prize and more.


Learn and discover simple things

Meihta Dwiguna Saputra's Knowledge Base

~In learning you will teach and in teaching you will (re)learn~

The Java Blog

Thoughts, tips and tricks about the Java programming language


that were shone when I got tempered!

%d bloggers like this: