Karthik Manduri

Not meant for public.

Friday, August 29, 2014

Web Services Sample Application Using SOAP

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.javapostsforlearning.webservices"
3.Create a simple java class named "HelloWorld.java" with following code

Web Services using SOAP


            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 protocol
  • 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.




    SOAP, WSDL and UDDI


    Simple Object Access Protocol(SOAP):

    SOAP is a protocol specification for exchanging structured information in the implementation of Web services in computer networks. It relies on XML as its message format.

    Web Service Description Language(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. 

    Elements of WSDL are:

    Description:
    It is the root element of a WSDL 2.0 file. It usually contains a set of name space declarations which are used throughout the WSDL file.  

    Types: 
    The WSDL types element describes the data types used by your web service.Data types are usually specified by XML schema.It can be described in any language as long as your web services API supports it.

    Binding:
    The WSDL binding element describes how your web service is bound to a protocol. In other words, how your web service is accessible. To be accessible, the web service must be reachable using some network protocol. This is called "binding" the web service to the protocol.

    Interface:
    The WSDL interface element describes the operations supported by your web service.It is similar to methods in programming language.Client can only call one opertion per request.  

    Service:
    It describes the endpoint of your web service. In other words, the address where the web service can be reached.

    Endpoint:
    The endpoint element describes the address of the web service. The endpoint binding attribute describes what binding element this endpoint uses.i.e. protocol with which you will access web service. The address attribute describes the URI at which you can access the service.

    Message: 
    The message element describes the data being exchanged between the Web service providers and consumers.

    Universal Description, Discovery and Integration(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 

    Advantages of Web Services

    Reuse already developed(old) functionality into new software:

    Lets understand with very simple example.Lets say you are developing a finance software for a company on java and you have old .net software which manages salary of employees.So rather then developing new software for employee part,you can use old software and for other parts like infrastructure you can develop your own functionalities.

    Usability :

    Web Services allow the business logic of many different systems to be exposed over the Web. This gives your applications the freedom to chose the Web Services that they need. Instead of re-inventing the wheel for each client, you need only include additional application-specific business logic on the client-side. This allows you to develop services and/or client-side code using the languages and tools that you want.

    Interoperability :

    This is the most important benefit of Web Services. Web Services typically work outside of private networks, offering developers a non-proprietary route to their solutions.Web Services also let developers use their preferred programming languages. In addition, thanks to the use of standards-based communications methods, Web Services are virtually platform-independent.

    Loosely Coupled:

    Each service exists independently of the other services that make up the application. Individual pieces of the application to be modified without impacting unrelated areas.

    Ease of Integration:

    Data is isolated between applications creating ’silos’. Web Services act as glue between these and enable easier communications within and across organisations.

    Deployability :

    Web Services are deployed over standard Internet technologies. This makes it possible to deploy Web Services even over the fire wall to servers running on the Internet on the other side of the globe. Also thanks to the use of proven community standards, underlying security (such as SSL) is already built-in.

    Web Services tutorial

    Source: java2blog.com

    In this post,we will see introduction to web services and some jargons of web services.


           Web service is a way of communication that allows inter-operability between different applications on different platforms, for example, a java based application on Windows can communicate with a .Net based one on Linux. The communication can be done through a set of XML messages over HTTP protocol.Web services are browsers and operating system independent service, which means it can run on any browser without the need of making any changes. Web Services take Web-applications to the Next Level.

    The World Wide Web Consortium (W3C) has defined the web services. According to W3C, “Web Services are the message-based design frequently found on the Web and in enterprise software. The Web of Services is based on technologies such as HTTP, XML, SOAP, WSDL, SPARQL, and others.”

    Lets say,you are a java developer and  you can publish your functions on internet or lan through java web service so any other developer(lets say .Net developer) can access your function.