SringSring

Monday, 22 September 2014

WebServices

1) Web services?
Web services are application components.
Web services communicate using open protocols.
Web services are self-contained and self-describing.
Web services can be discovered using UDDI.
Web services can be used by other applications.
HTTP and XML is the basis for Web services.

2) Why you need to learn web services:
Reuse already developed(old) functionality into new software:
Usability .
Interoperability .
Loosely Coupled.
Ease of Integration.
Deployability.

3) Some idioms used in Web services:
SOAP   : Simple Object Access Protocol
WSDL   : 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.
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.
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.
        Message:   The message element describes the data being exchanged between the
                                  Web service providers and consumers.


   UDDI   : 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.


4) Web service design approaches ?
A) Contract last or Bottom up approach:
When using contract last approach,you first write your java code then you create web service contract(WSDL) .There are various kinds of tools which can generate WSDL on the basis of java code.
B) Contract first or Top Down Approach :
        It  is reverse of contract first.Here you first define web service contract.You define all the elements of WSDL first then after that you create your java logic.

5) Different types of webservices in java? where to start? [closed]
        [Difference between these different type of webservices]

Ans)   There are mainly two types SOAP and RESTFULL

    A) SOAP Web Services :
These are standard-based and supported by almost every software platform:
SOAP can be over any transport protocols such HTTP, FTP, STMP, JMS etc.
They rely heavily in XML and have support for transactions, security, asynchronous messages.
It’s a pretty big and complicated standard, but covers almost every messaging situation.
 JAX-WS standard and Apache Axis2 (both are API's )are used for build/consume WServices.

SOAP Services are Applicable for below scenarios :
If you require asynchronous processing.
If you need formal contract/Interfaces.
In your service operations are stateful:
For example, you store information/data on a request and use that stored data on the next one.

    B) RESTful Services  : Representational State Transfer (RESTful) web services.
          These relies of HTTP protocol and verbs (GET, POST, PUT, DELETE)
  to interchange messages in any format,
                   Preferable JSON and XML.
   It’s a pretty simple and elegant architectural approach.
   REST you can use Restlets or Spring REST Facilities.
   JAX-RS is the API for REST-based services.
   REST has no WSDL interface definition.

   RESTful Services are Applicable for below scenarios :
If you have limited bandwidth.
If your operations are stateless: No information is preserved from one invocation to the next one, and each request is treated independently.
For stateless CRUD (Create, Read, Update, and Delete) operations.
Caching situations: The information needs to be cached.
HTTP     CRUD Equivalent
==============================
GET      read
POST     create,update,delete
PUT      create,update
DELETE   delete

6) A Simple SOAP Example :
        Example of a simple request-response in SOAP for a stock quote. Here the transport binding is HTTP.

The request:

GET /StockPrice HTTP/1.1
Host: example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
   xmlns:s="http://www.example.org/stock-service">
   <env:Body>
     <s:GetStockQuote>
          <s:TickerSymbol>IBM</s:TickerSymbol>
     </s:GetStockQuote>
   </env:Body>
</env:Envelope>


7) Summary and Pros/Cons

*** SOAP ***

Pros:

       Langauge, platform, and transport agnostic.
       Designed to handle distributed computing environments.
       Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors.
       Built-in error handling (faults).
       Extensibility.
       Cons:
                       Conceptually more difficult, more "heavy-weight" than REST.
       More verbose.
       Harder to develop, requires tools.
          *** REST ***

  Pros:
                       Language and platform agnostic.
       Much simpler to develop than SOAP.
Small learning curve, less reliance on tools.
Concise, no need for additional messaging layer.
Closer in design and philosophy to the Web.
Cons:
                     Assumes a point-to-point communication model--not usable for distributed computing environment where message may go through one or more intermediaries.
     Lack of standards support for security, policy, reliable messaging, etc., so services that have more sophisticated requirements are harder to develop ("roll your own").
     Tied to the HTTP transport model.

7) Basic questions
   1) Do you really think that it (JAX-RPC) is completely obsolete? I think you need to understand its basics too for giving support to existing services. Isn't it?

Ans) Yes it is obsolete. It is the old specification. Don't need to look into it.

2) Is it possible to implement service without annotations?
Ans ) Of course it is. All tutorials usually show example of starting a Web Service using annotations and also starting a Web Service from a WSDL i.e. you first create a WSDL and the web service (stubs) are autogenerated

3) What is difference between SOA and Web-Services?
Ans) Web Services are used as one of the implementation technologies to offer SOA.
There is no book specifying differences between these 2 technologies since one is an implementation component of the other.




4) Sample WSDL file :

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://webservices.javapostsforlearning.arpit.org" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservices.javapostsforlearning.arpit.org" xmlns:intf="http://webservices.javapostsforlearning.arpit.org" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://webservices.javapostsforlearning.arpit.org" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="sayHelloWorld">
    <complexType>
     <sequence>
      <element name="name" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="sayHelloWorldResponse">
    <complexType>
     <sequence>
      <element name="sayHelloWorldReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>
   <wsdl:message name="sayHelloWorldRequest">
      <wsdl:part element="impl:sayHelloWorld" name="parameters"/>
   </wsdl:message>
   <wsdl:message name="sayHelloWorldResponse">
      <wsdl:part element="impl:sayHelloWorldResponse" name="parameters"/>
   </wsdl:message>
   <wsdl:portType name="HelloWorld">
      <wsdl:operation name="sayHelloWorld">
         <wsdl:input message="impl:sayHelloWorldRequest" name="sayHelloWorldRequest"/>
         <wsdl:output message="impl:sayHelloWorldResponse" name="sayHelloWorldResponse"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld">
      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="sayHelloWorld">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="sayHelloWorldRequest">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:output name="sayHelloWorldResponse">
            <wsdlsoap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="HelloWorldService">
      <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld">
         <wsdlsoap:address location="http://localhost:8080/SimpleSOAPExample/services/HelloWorld"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>


5) Web service design approaches:
A) Contract last or Bottom up approach:
When using contract last approach,you first write your java code then you create web service contract(WSDL) .There are various kinds of tools which can generate WSDL on the basis of java code.
B) Contract first or Top Down Approach :
It  is reverse of contract first.Here you first define web service contract.You define all the elements of WSDL first then after that you create your java logic.
6) Different types of webservices in java? where to start? [closed]
[Difference between these different type of webservices]

1) SOAP Web Services :
These are standard-based and supported by almost every software platform:
SOAP can be over any transport protocols such HTTP, FTP, STMP, JMS etc.
They rely heavily in XML and have support for transactions, security, asynchronous messages.
It’s a pretty big and complicated standard, but covers almost every messaging situation.

JAX-WS standard and Apache Axis2 (both are API's )are used for build/consume Web Services.

SOAP Services are Applicable for below scenarios :
If you require asynchronous processing.
If you need formal contract/Interfaces.
In your service operations are stateful:
For example, you store information/data on a request and use that stored data on the next one.

2) RESTful Services  : Representational State Transfer (RESTful) web services.
  These relies of HTTP protocol and verbs (GET, POST, PUT, DELETE)
  to interchange messages in any format,
  Preferable JSON and XML.
  It’s a pretty simple and elegant architectural approach.
  REST you can use Restlets or Spring REST Facilities.
  JAX-RS is the API for REST-based services.
 
  REST has no WSDL interface definition
RESTful Services are Applicable for below scenarios :
If you have limited bandwidth.
If your operations are stateless: No information is preserved from one invocation to the next one, and each request is treated independently.
For stateless CRUD (Create, Read, Update, and Delete) operations.
Caching situations: The information needs to be cached.
HTTP     CRUD Equivalent
==============================
GET      read
POST     create,update,delete
PUT      create,update
DELETE   delete


7) Here are couple things to read or google more :

main difference between SOAP and RESTful web services in java http://www.ajaxonomy.com/2008/xml/web-services-part-1-soap-vs-rest

It's up to you what do you want to learn first. I'd recommend you take a look at the CXF framework. You can build both rest/soap services.

Q2) Here are couple of good tutorials for soap (I had them bookmarked) :

http://united-coders.com/phillip-steffensen/developing-a-simple-soap-webservice-using-spring-301-and-apache-cxf-226

http://www.benmccann.com/blog/web-services-tutorial-with-apache-cxf/

http://www.mastertheboss.com/web-interfaces/337-apache-cxf-interceptors.html

8) A Simple SOAP Example

Putting it all together, below is an example of a simple request-response in SOAP for a stock quote. Here the transport binding is HTTP.

The request:

GET /StockPrice HTTP/1.1
Host: example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
   xmlns:s="http://www.example.org/stock-service">
   <env:Body>
     <s:GetStockQuote>
          <s:TickerSymbol>IBM</s:TickerSymbol>
     </s:GetStockQuote>
   </env:Body>
</env:Envelope>


9) Summary and Pros/Cons

*** SOAP ***

Pros:

Langauge, platform, and transport agnostic
Designed to handle distributed computing environments
Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors
Built-in error handling (faults)
Extensibility
Cons:

Conceptually more difficult, more "heavy-weight" than REST
More verbose
Harder to develop, requires tools
*** REST ***

Pros:

Language and platform agnostic
Much simpler to develop than SOAP
Small learning curve, less reliance on tools
Concise, no need for additional messaging layer
Closer in design and philosophy to the Web
Cons:

Assumes a point-to-point communication model--not usable for distributed computing environment where message may go through one or more intermediaries
Lack of standards support for security, policy, reliable messaging, etc., so services that have more sophisticated requirements are harder to develop ("roll your own")
Tied to the HTTP transport model
10) Baseic questions
   1) Do you really think that it (JAX-RPC) is completely obsolete? I think you need to understand its basics too for giving support to existing services. Isn't it?

Ans) Yes it is obsolete. It is the old specification. Don't need to look into it.

2) Is it possible to implement service without annotations?
Ans ) Of course it is. All tutorials usually show example of starting a Web Service using annotations and also starting a Web Service from a WSDL i.e. you first create a WSDL and the web service (stubs) are autogenerated

3) What is difference between SOA and Web-Services?
Ans) Web Services are used as one of the implementation technologies to offer SOA.
There is no book specifying differences between these 2 technologies since one is an implementation component of the other.

11) What is wsgen and wsimport?




No comments:

Post a Comment