Client artifacts generated in a java web service

Rajkumar

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.

kamoor

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.

Reference 1 | Reference 2

JAX-RPC is bit older, you can read history from wikipedia

Have fun

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I prevent JAXBElement<String> from being generated in a CXF Web Service client?

Error when compiling a basic web service client in Java

Java Web Service client basic authentication

java web service client, adding http headers

Problem generating Java SOAP web services client with JDK tool wsimport from a WSDL generated by a .NET 2.0 application

Eclipse Generated Web Service Client Extremely Slow

Java Spring Web Service Client Fault Handling

C# client for Java Web Service - data interoperability issue

How to generate a web service client in Java using Eclipse

Connection details & timeouts in a java web service client

Best ways to manage generated artifacts for web service/xml bindings in a java webapp/client?

dynamic proxy soap web service client in java?

Generate web service client secure policy from .wsdl for java

Web service using php soap server and java client

Using Xtext generated artifacts

What is the entry point in a CXF generated web service?

Client in REstful web service

Java AXIS2 web-service client

Displaying jasper report generated by a web service

Dynamic Web Service Client

.NET web service and php client

response produced exception – java client / WCF web service

java web service client trying to access web service through SSL - TrustManagerFactoryImpl is not initialized

How to call web service client in java eclipse

Difference between web client and web service?

How to consume liferay web service written in liferay from java client?

dataset .net cannot resolve on java web service client

web-service client - with keystore

Service being generated but not client protoc