From time to time I have to implement some SOAP based web services. Usually these web services are used for application integration so the contract first approach is used where one creates the WSDL document first.
To create the server stub from the WSDL document I found out that using Maven in combination with NetBeans is the most straight forward approach.
Just choose “New File” from the menu:
package ch.simas.demo.ws; import javax.ejb.Stateless; import javax.jws.WebService; @WebService(serviceName = "CalculatorService", portName = "ICalculator", endpointInterface = "org.example.ICalculator", targetNamespace = "http://Example.org", wsdlLocation = "META-INF/wsdl/calculator.wsdl") @Stateless public class CalculatorService { public java.lang.Integer add(java.lang.Integer a, java.lang.Integer b) { //TODO implement this method throw new UnsupportedOperationException("Not implemented yet."); } public java.lang.Integer subtract(java.lang.Integer a, java.lang.Integer b) { //TODO implement this method throw new UnsupportedOperationException("Not implemented yet."); } }
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlFiles>
<wsdlFile>calculator.wsdl</wsdlFile>
</wsdlFiles>
<staleFile>${project.build.directory}/jaxws/stale/calculator.stale</staleFile>
</configuration>
<id>wsimport-generate-calculator</id>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>webservices-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<configuration>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
<xnocompile>true</xnocompile>
<verbose>true</verbose>
<extension>true</extension>
<catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
<target>2.0</target>
</configuration>
</plugin>