☰ See All Chapters |
How to pass the input to SOAP web service
So far we learnt just to consume the web service which is exposed statically. Suppose we need the response based the date, we have to pass the input to web service. So, how to pass the input to web services? And how to get the input from clients?. Many times in real time applications are developed as web service those accepting complex input data and complex output data. In previous chapter we learnt to return object from web service. In the chapter we will learn to accept the input from web service. Follow the below steps to learn to accept input from web service.
Person.java
package com.java4coding;
import java.io.Serializable;
public class Person implements Serializable{
private String name; private int age; private int id;
public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public int getId() { return id; } public void setId(int id) { this.id = id; } @Override public String toString(){ return id+"::"+name+"::"+age; } } |
PersonService.java
package com.java4coding;
import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style;
@WebService @SOAPBinding(style = Style.RPC) //@SOAPBinding(style = Style.DOCUMENT) public interface PersonService{
@WebMethod Person getPerson(Person person);
} |
PersonServiceImpl.java
package com.java4coding;
import javax.jws.WebService; import javax.xml.bind.annotation.XmlElement;
//Service Implementation @WebService(endpointInterface = "com.java4coding.PersonService") public class PersonServiceImpl implements PersonService{
@Override @XmlElement(required = true) public Person getPerson(Person person) { return person; } } |
PersonPublisher.java
package com.java4coding;
import javax.xml.ws.Endpoint;
//Endpoint publisher public class PersonPublisher{
public static void main(String[] args) { Endpoint.publish("https://localhost:7779/ws/person", new PersonServiceImpl()); System.out.println("done"); } } |
Output:
To get output run PersonPublisher.java as java application.
Access the web services at "https://localhost:7779/ws/person?wsdl"
All Chapters