Showing posts with label SOAP web service. Show all posts
Showing posts with label SOAP web service. Show all posts

Thursday, March 28, 2013

SOAP web service example in java using eclipse

In this post,we will see SOAP web service example.

Web service Tutorial Content:

Part-1:Introduction to web services
Part-2:SOAP web service introduction 
Part-3:RESTful web service introduction
Part-4:SOAP web service example in java using eclipse
Part-5:JAX-WS web service eclipse tutorial
Part-6:JAX-WS web service deployment on tomcat 
Part-7:Create RESTful web service in java(JAX-RS) using jersey

In this post,we will create hello world SOAP web service example in eclipse.Eclipse provides good API for creating web services.Eclipse will do all work for you-creating WSDL,stub,endpoints etc.

Steps for creating web services in eclipse:

1.Create new dynamic web project and name it "SimpleSOAPExample".
 2.Create new package named "org.arpit.javapostsforlearning.webservices"

3.Create a simple java class named "HelloWorld.java"
package org.arpit.javapostsforlearning.webservices;

public class HelloWorld {

    public String sayHelloWorld(String name)
    {
        return "Hello world from "+ name;
    }
}

4.Right click on project->new->web service


 5.Click on next.

In service implementation text box,write fully qualified class name of above created class(HelloWorld.java) and move both above slider to maximum level (i.e. Test service and Test Client level) and click on finish.You are done!!A new project named "SimpleSOAPExampleClient" will be created in your work space.


6.
Click on start server.
7.After clicking start server,eclipse will open test web service API.With this test API,you can test your web service.


You are done!!.But to understand more about web services,you need to explore more.You can explore above created "SimpleSOAPExampleClient" and learn more about web services.
In next post,you will see JAXWS web service example.


SOAP web service tutorial

In this post,we will see introduction to SOAP web services.

Web service Tutorial Content:

Part-1:Introduction to web services
Part-2:SOAP web service introduction 
Part-3:RESTful web service introduction
Part-4:SOAP web service example in java using eclipse
Part-5:JAX-WS web service eclipse tutorial
Part-6:JAX-WS web service deployment on tomcat 
Part-7:Create RESTful web service in java(JAX-RS) using jersey

Simple Object Access Protocol (SOAP) is a standard protocol specification for message exchange based on XML. Communication between the web service and client happens using XML messages.

A simple web service architecture have two components
  • Client
  • Service provider

    So as in above diagram,how client will communicate to service provider.So in order to communicate client must know some information for e.g.
    • Location of webservices server
    • Functions available,signature and return types of function.
    • Communication protocal
    • Input output formats
    Service provider will create a standard XML file which will have all above information.So If this file is given to client then client will be able to access web service. This XML file is called WSDL.

    What is WSDL?

    WSDL stands for Web Service Description Language. It is an XML file that describes
    the technical details of how to implement a web service, more specifically the URI,
    port, method names, arguments, and data types. Since WSDL is XML, it is both
    human-readable and machine-consumable, which aids in the ability to call and bind to
    services dynamically.using this WSDL file we can understand things like,
    •     Port / Endpoint – URL of the web service
    •     Input message format
    •     Output message format
    •     Security protocol that needs to be followed
    •     Which protocol the web service uses

    Ways to access web service:

    There are two ways to access web service.
    • If Service provider knows client:If service provider knows its client then it will provide its wsdl to client and client will be able to access web service.


    • Service provider register its WSDL to UDDI and client can access it from UDDI:UDDI stands for Universal Description, Discovery and Integration.It is a directory service. Web services can register with a UDDI and make themselves available through it for discovery.So following steps are involved.
        1. Service provider registers with UDDI.
        2. Client searches for service in UDDI.
        3. UDDI returns all service providers offering that service.
        4. Client chooses service provider
        5. UDDI returns WSDL of chosen service provider.
        6. Using WSDL of service provider,client accesses web service.

        In next post,we will see SOAP hello world example in java using eclipse.