We will create the needed classes to generate a Web Service client from its WSDL.
We will base in the HelloWorld project, and here will add the security. In this project we response with a Hello for the name which sent as argument through the Web Service.
In order to generate the classe we will use SoapUI:
We must to locate in our hard disk the wsimport.bat tool, downloaded with the SUN standard package implementation (of JAX-WS):
It generates a folder with sources and other with compiled classes:
To write the client helped with this classes is as easy as this:
package client; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.BindingProvider; public class HelloClient { public static void main(String[] args) { HelloService service = null; try { // Creamos el servicio con el WSDL URL wsdlLocation = new URL("http://localhost:7001/wsc/HelloService?WSDL"); String targetNamespace="http://services/"; String name="HelloService"; service = new HelloService( wsdlLocation, new QName(targetNamespace, name)); Hello port = service.getHelloPort(); // Añadimos capacidades de seguridad a la llamada BindingProvider provider = (BindingProvider) port; provider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "user"); provider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "12345678"); //Mostramos el resultado System.out.println(port.sayHello(args[0])); } catch (MalformedURLException e ) { e.printStackTrace(); } } } |
Hello,
I followed the same process stated here but i get the following error:
JAXWS_HOME must be set before running this script
I then set the JAXWS_HOME but still it gives the same error. Please help
Thanks in Advance
Samruddhi
Thanks for the post, it was simple and very helpful.
cheers from brazil \o/
I must say you have hi quality content here. Your website should
go viral. You need initial boost only. How to get it?
Search for: Etorofer’s strategies