SOAP Web Service Server and Client Example With Apache CXF and Eclipse

Let’s create a simple standalone web service example with Apache CXF. First, we are going to build a server then generate a client to send a request to our web service.

1- Building a server

– Create a new Dynamic Web Project
– Right click the project and Configure > Convert to Maven Project
– Change build path source folder as src/main/java

Project Explorer looks like:
cxf2

Run as Java Application and the server starts…
cxf3

We can test it our web service via SOAPUI
– Create a new SOAP project with initial WSDL address http://localhost:9000/HelloWorld?wsdl
cxf4

So it works!

2- Building a client

Initially, we should configure Eclipse to work with CXF.
– Install CXF binary from official site
– Set path via Eclipse > Window > Preferences > Web Services > CXF 2.x Preferences
cxf1

Then create a new project for client,

– Create a new Dynamic Web Project
– Right click the project and Configure > Convert to Maven Project
– Change build path source folder as src/main/java
– File > New > Other > Web Service Client

cxf5
cxf6

If you faced with an error like “Failed to read schema document ‘xjc.xsd’, because ‘file’ access is not allowed due to restriction set by the accessExternalSchema property” while creating a client, here is the solution:
http://stackoverflow.com/q/23011547/1091666

Project Explorer looks like:
cxf7

Create a Main class for the client and run it.

cxf8

That’s all folks!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: