I have worked in quite some web service projects using JAX-WS implementation such as Axis. Artifacts are generated by using the IDE and it works. But, I would like to know the client artifacts generated and what they do. It would be helpful if you can provide any definitive guide or source could be given.
I am aware of how to generate the artifact. But couldn't find any source which describes the client artifacts generated and what they do.
As you already know, JAX-WS is intended to provide a Java API specification for XML Web Services. As an object oriented Java developer we don't want to deal with raw XML in code. We instead like object-oriented representation of XML file so that we only deal with classes and objects.
Service Provider will create a web service and expose it's data transfer contract using an XML definition (WSDL). Now client wants to use this web service by creating XML input file(SOAP message) and communicate with server.
So you received the WSDL file which essentially tells you how to access service (service end point), what are the operations exposed, What is the input schema for each service, what is the output schema, error schema so on..
One way to communicate with a web service is to manually look at the schema and create an XML (SOAP) message and try to connect to the service. Which is extremely difficult, error prone, not readable and maintainable. That’s why we have a specification to convert huge, complicated XML schema to more developer friendly, object oriented classes, which represents exactly the same XML elements defined in WSDL. It also generates factory classes to create instance of any POJO classes.
Take a simple WSDL file and generate client classes using wsimport. You can see, it generated Object Oriented representation of Input and Output XML, interfaces created for Service and Operations, a web service client which represent the whole service, Object Factory which helps you create instance of any data transfer classes. JAX-WS will use all these interfaces and classes to generate final SOAP message to invoke web service.
All you need to do is, Create object of input and make a call to web service operation, JAX-WS implementation will take care of all the heavy lifting of converting your object in to SOAP and making service calls, then convert response SOAP message back to object oriented representation and return to your application.
For example: Take a Calculator Service which has Add and Substract operations. Each Operation expects specific type of SOAP message. wsimoport will generate,
A high level WebService class with a definition of end point (ICalculator)
@WebServiceClient(name = "CalculatorService",...)
public class CalculatorService
extends Service
{
….
@WebEndpoint(name = "ICalculator")
public ICalculator getICalculator(WebServiceFeature... features) {
.....
}
…
}
An ICalculator interface to define each Operations,
@WebService(name = "ICalculator", targetNamespace = "http://Example.org")
public interface ICalculator {
….
@WebMethod(operationName = "Add", action = "http://Example.org/ICalculator/Add")
@WebResult(name = "result", targetNamespace = "http://Example.org")
@RequestWrapper(localName = "Add", targetNamespace = "http://Example.org", className = "org.example.Add")
@ResponseWrapper(localName = "AddResponse", targetNamespace = "http://Example.org", className = "org.example.AddResponse")
public Integer add(
@WebParam(name = "a", targetNamespace = "http://Example.org")
Integer a,
@WebParam(name = "b", targetNamespace = "http://Example.org")
Integer b);
….
}
Data Transfer Object to represent all request and response format,
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Add")
public class Add {
protected Integer a;
protected Integer b;
…. All getter and setter
}
and some other factory classes too. You can see all these annotations are defined by JAX-WS specification and used by JAX-WS implementation to generate SOAP message and facilitate communication. You don't deal with XML anymore in application code. You just do object oriented programming.
JAX-RPC is bit older, you can read history from wikipedia
Have fun