Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

Wednesday, October 9, 2013

Understanding web service in simple words


What is a Web Service ? :
  • A webservice is a software function provided at a network address over the web
  • It is supposed to be "always on"
  • Web services are really nothing more than a request/ response mechanism that allows a client to remotely access/ modify data.

Types of Web Services :

  1. Big Web Services  (Basically StateFull)
( JAX-WS provides the functionality for “big” web services )
  • Big web services use XML messages that follow the Simple Object Access Protocol (SOAP) standard.



A SOAP-based design must include the following elements.

  • A formal contract ,WSDL can be used to describe the details of the contract .
  • The architecture must address complex nonfunctional requirements .
Examples include transactions, security, addressing, trust, coordination, and so on. For More on JAX-WS Refer this link 

Basic Component of State Full Webservices

What is WSDL?
  •  Web Services Description Language
  • based on XML
  • describe Web services
  • locate Web services

What is SOAP?
  • Simple Object Access Protocol
  • format for sending messages
  • platform independent
  • based on XML

What is UDDI?
UDDI is a directory service where companies can register and search for Web services.



 2)  RESTful Web Services (Stateless)
         (  JAX-RS provides the functionality for Representational State Transfer (RESTful) web services  )
         
REST is well suited for basic, ad hoc integration scenarios. RESTful web services, often better integrated with HTTP than SOAP-based services are, do not require XML messages or WSDL service–API definitions .
developing RESTful web services is inexpensive .

Appropriate for  following conditions .

  1. The web services are completely stateless (A stateless server is a server that treats each request as an independent transaction that is unrelated to any previous request.) A good test is to consider whether the interaction can survive a restart of the server.
  1. A caching infrastructure can be leveraged for performance. If the data that the web service returns is not dynamically generated and can be cached.
  2. producer and service consumer have a mutual understanding of the context and content being passed along.

Tuesday, October 8, 2013

Learn JAX WS in Few Seconds..

Implementing web service Endpoint/Client with JAX WS

Developing Web Service End Point
1) In Eclipse  create a java project "JAXWS-Server".
2) Create JAXWS-Service Endpoint Interface:

--------------------------------------------------------------------------
package mysimple.example.define;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface Greeting {
@WebMethod String sayHello(String name);
}
-------------------------------------------------------------------------- 

3) Create JAXWS-Service Endpoint Implementation class:

-------------------------------------------------------------------------- 
package mysimple.example.define;
import javax.jws.WebService;

@WebService(endpointInterface = "mysimple.example.define.Greeting")
public class GreetingImpl implements Greeting  {

@Override
public String sayHello(String name) {
return "Hello, This is simplest JAX-WS example By :: " + name;
}
}
--------------------------------------------------------------------------  

4) Create Endpoint Publisher class:

-------------------------------------------------------------------------- 
package mysimple.example.publish;
import javax.xml.ws.Endpoint;

import mysimple.example.define.GreetingImpl;

public class WSPublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/WS/Greeting",new GreetingImpl());
}
}
-------------------------------------------------------------------------- 

5) Run the WSPublisher….and your WebService is published.


Developing Web Service Client :

1) In eclipse create a new java project JAXWS-Client
2) we need to generate the client stubs by following command(on the src path)

Command : wsimport -keep -verbose http://localhost:8080/WS/Greeting?wsdl


  1. Remove all the class files
  2. Create the  Client Class which will be dependent on the stubs

-------------------------------------------------------------------------- 
package mysimpleexample.client;
import mysimple.example.define.Greeting;
import mysimple.example.define.GreetingImplService;



public class Client {
public static void main(String[] args){

GreetingImplService service = new GreetingImplService();
Greeting greeting = service.getGreetingImplPort();
System.out.println("------->>  Call Started");
System.out.println(greeting.sayHello("Manish_Kumar_Jaiswal"));
System.out.println("------->>  Call Ended");
}
}
-------------------------------------------------------------------------- 

  1. Output :

------->>  Call Started
Hello, This is simplest JAX-WS example By :: Manish_Kumar_Jaiswal
------->>  Call Ended