Skip to main content

Sample Web service and client creation using WSDL with Maven and JAX-WS

How to generate client via WSDL file

By executing following command on linux bash command line, cloud be obtain the service port classes

> wsimport -keep -verbose http://compA.com/ws/HelloService.wsdl -b binding.xml
OR
> wsimport -keep -verbose /home/malith/HelloService.wsdl -b binding.xml

Note : The binding xml is need to avoid generating JAXB element contents
------

How to create web service


By above code generation, we can obtain Interface class which contains the service bridge.
We could be wright sample web service by implementing the interface by additionally adding teh @WebService annotation
Create the sun-javaws.xml in WEB-INF folder to define web service mappings

E.g.

@WebService(name = "Hello_", targetNamespace = "http://www.examples.com/wsdl/HelloService.wsdl")
public class HelloWebService implements HelloPortType {

    /**
     * @param firstName
     * @return returns java.lang.String
     */
    public String sayHello(@WebParam(name = "firstName", partName = "firstName") String firstName) {
        System.out.println("Name received : " + firstName);
        return "Hello "+ firstName+ " welcome to the web service";
    }
}

Deploy the web service

Build the above project using maven and deploy the ***.war archive in tomcat.

Type in web browser like http://localhost:8080/webservice-1.0.0/hello, then we can visible the deployed web service details

Refer code here

Clone sample code here

git clone https://github.com/malithmeee/hello-web-service.git

Comments

Popular posts from this blog

Birt Dynamic Table Creation from JDBC Mysql Connection with Maven

In this post refers how to create dynamic Birt reports using given customizing fields list using Birt Runtime 4.2.2 Step 01 : First need to download birt runtime. Download from here For view/Edit the rptdesign files, it's better to use Eclipes 4.2.2 Birt integration. Download eclipes here Step 02 : Extract the birt-runtime-4_2_2. and set the birt runtime home environment variable. e.g. in my case i'm set the environment variable in .bash_profile since i'm using Fedora. (we can specify the Birt home in java code as wel) export BIRT_HOME=/home/malith/usr/eclips/birt-runtime-4_2_2 Step 03 : Create Maven project and insert the dependency for Birt Runtime         <dependency>             <groupId>org.eclipse.birt.runtime</groupId>             <artifactId>org.eclipse.birt.runtime</artifactId>  ...

Create clone of git project from existing code without do new clone

In this article, I will guide you how to create a clone of a existing project by using the already cloned code set which available in another computer. When you going to clone the project from remote repository, it's need to download the project form the remote. Trouble start if the project got more capacity and slow internet connections or temporary disconnection to clone new one. Step 01.  Go to the project location of code existing place by console. (I'm using linux terminal) Step 02. Execute following command at the project place. git archive --format zip --output /full/path/to/myproject.zip master Project code has exported to the myproject.zip, but not included the .git folder. Take both myproject.zip file and .git folder to another computer or another place of your computer Step 3. Extract the zip and copy the .git folder into it. Step 4. Go inside to the project and take git pull (If internet connection available). Now it's working as a newly clone...

EJB3 Stateless Maven example with Jboss Application server

Step 1 : Download jboss 5.1 application server from below (Which supporting for JDK 1.6) http://jbossas.jboss.org/downloads Extract and start the Jboss server. Step 2 : Create sample maven project as below <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">     <modelVersion>4.0.0</modelVersion>     <groupId>ejb</groupId>     <artifactId>ejb-stateless</artifactId>     <version>1.0-SNAPSHOT</version>     <dependencies>         <dependency>             <gro...