Java

Saturday 16 March 2013

web services Introduction



Introduction to web services:

 

TUTIORALS FROM MADHAV:

     JAVA-SERVLETS     JAVA-JDBC     JAVA-JSP       HIBERNATE-SHCEMABASED 

    SPRING-AOP-ANNOTATIONS      SPRING -DAO     SPRIN-MVC     SPRING-SECUTITY

     SPRING-DATA-JPA     REST-WEB-SERVICE     STRUTS2HIBERNATE    GWT.... 




1.What are web services?
2.Types of web servicesa

What are web services?


  •   Web services are client and server applications that communicate over the World Wide Web (WWW) hyper text transfer protocol (HTTP)
  •   As described by the www consortium (W3C), web services provide a standard means of interoperating between software applications running on a variety of platform and frameworks.
  •  Web services are characterized by great interoperability and extensibility, as well as the machine-process able descriptions,
  • Web services can be combined in a loosely coupled way to achieve complex operations.
  •  Programs providing simple services can interactive with each other to deliver sophisticated added value services.

Types of web services:


The two types:
1.big web services
2.restful web services.

  • In java, jax-ws provides the functionally for big web services.
  •   Big web services use XML messages that follow the simple object access protocol (SOAP) standard, an xml language defining a message architecture and message formats.
  •   Such systems often contain a machine-readable description of the operations offered by the service, written in the web services description language (WSDL),and xml language for defining interfaces syntactically.
  •   The soap message format and the WSDL interface definition language have gained widespread adoption.
  •  Many development tools, such as netbeans IDE, can reduce the complexity of developing web service applications. 
  •   A SOAP –based design must include the following elements.
  •   A format contract must be established to describe the interface that the web service offers.
  • WSDL can be used to describe the details of the contract, which may include messages,Operations, bindings, and the location of the web services
  •  In java EE6 ,JAX-RS provides the functionality for representational state transfer(restful) web services.
  •   Rest is well suited for basic, ad hoc integration scenarios.





TUTIORALS FROM MADHAV:

     JAVA-SERVLETS     JAVA-JDBC     JAVA-JSP       HIBERNATE-SHCEMABASED 

    SPRING-AOP-ANNOTATIONS      SPRING -DAO     SPRIN-MVC     SPRING-SECUTITY

     SPRING-DATA-JPA     REST-WEB-SERVICE     STRUTS2HIBERNATE    GWT....

 Related topics:

websevice jax ws rpc example


websevice jax-ws-rpc style:
-----------------------------------

     JAVA-SERVLETS     JAVA-JDBC     JAVA-JSP       HIBERNATE-SHCEMABASED 

    HIBERNATE-ANNOTATIONS     SPRING-IOC       SPRING –AOP-SCHEMABASED   

    SPRING-AOP-ANNOTATIONS      SPRING -DAO     SPRIN-MVC     SPRING-SECUTITY

     SPRING-DATA-JPA     REST-WEB-SERVICE     STRUTS2HIBERNATE    GWT.... 





NOTE:   1)  maven dependeccy pom.xml  , we can get from previous example.
              

SayHaiService .java
--------------

package madhav;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface SayHaiService {
    @WebMethod
    public String sayHai(String hai);
   
}

SayHaiServiceImpl .java
---------------
package madhav;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(endpointInterface = "madhav.SayHaiService")
public class SayHaiServiceImpl implements SayHaiService{

    @Override
    @WebMethod
    public String sayHai(String hai) {
        return hai;
    }

}


Publish .java
--------------

package madhav;
import javax.xml.ws.Endpoint;
public class Publish {
    public static void main(String[] args) {
        Endpoint.publish("http://localhost:8080/webservice-JAX-WS-RPC/sayhai", new SayHaiServiceImpl());
        System.out.println("say hai service is published");
    }

}




Client .java
---------------
package madhav;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class Client {
    public static void main(String[] args) {
        URL url = null;
        try {
            url = new URL("http://localhost:8080/webservice-JAX-WS-RPC/sayhai?wsdl");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        QName qname = new QName("http://madhav/",
                "SayHaiServiceImplService");

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

        SayHaiService sayHaiService = service.getPort(SayHaiService.class);

        System.out.println(sayHaiService.sayHai("hai how r u"));

    }

}
TUTIORALS FROM MADHAV:

     JAVA-SERVLETS     JAVA-JDBC     JAVA-JSP       HIBERNATE-SHCEMABASED 

    HIBERNATE-ANNOTATIONS     SPRING-IOC       SPRING –AOP-SCHEMABASED   

    SPRING-AOP-ANNOTATIONS      SPRING -DAO     SPRIN-MVC     SPRING-SECUTITY

     SPRING-DATA-JPA     REST-WEB-SERVICE     STRUTS2HIBERNATE    GWT....