Invoke SOAP web service using Client Jars(wsimport command)

Step 1 : Open Command prompt(Windows + R + Enter) and traverse to folder for downloading client jars. e.g : D:\Development\Soap.
Step 2: Run below mentioned command:
wsimport -clientjar soapService.jar http://localhost:8080/SOAPWebSErvice/services/EmployeeController?wsdl

wsimport – To download cient jar/source code on local machine.
-clientjar – To bundle all the jars and source code into a single bundle.
soapService.jar - Jar file name.
http://localhost:8080/SOAPWebSErvice/services/EmployeeController?wsdl – WSDL url where service is deployed.

Step 3: Create New Java Project and add SoapClient.java file as below :

package com.client;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import com.test.controller.EmployeeController;
import com.test.model.Employee;

public class SoapClient {

public static void main(String[] args) throws Exception {

final URL url = new URL("http://localhost:8080/SOAPWebSErvice/services/EmployeeController?wsdl");

// 1st argument service URI, refer to wsdl document above
// 2nd argument is service name, refer to wsdl document above
final QName qname = new QName("http://controller.test.com", "EmployeeControllerService");

final Service service = Service.create(url, qname);

final EmployeeController hello = service.getPort(EmployeeController.class);

final Employee employee = new Employee();
employee.setId("123456");
employee.setName("Mohsin");

final Employee employeeResponse = hello.setEmployee(employee);
System.out.println(employeeResponse.getId());

}

}
Step 4: Now the client jars will be downloaded under D:\Development\Soap folder.
Import downloaded jar(soapService.jar) file into your java project.

Comments

Popular posts from this blog

Edit/Modify existing PDF using Java(iText)

Verify Digital Signature in PDF using Java(iText) and cacerts

Steps to create SOAP Web service using Eclipse