Ans: Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). Web services provide a standard means of inter operating between software applications running on a variety of platforms and frameworks.
Main characteristics of the Web Services are :
1. Interoperability
2. Extensibility
3. Machine processable descriptions.
for example in simple words , when we call somebody so the person dialing and calling is the client application , while person receiving the call is server applicationand "hello" word is the protocol as similar to HTTP request .
Ans: SOA (Service-Oriented Architecture) is an architectural pattern that makes possible for
services to interact with one another independently.
Web Services is a realization of SOA concept, that leverages XML, JSON, etc. and common Internet protocols such as HTTP(S), SMTP, etc.
SOA is a system-level architectural style that tries to expose business. WOA is an interface-level architectural style that focuses on the means by which these service capabilities are exposed to consumers.
Ans:
SOAP (Simple Object Access Protocol) is a transport protocol for sending and receiving requests and responses on XML format, which can be used on top of transport protocols such as HTTP, SMTP, UDP, etc.
REST (REpresentational State Transfer) is an architectural style by which data can be transmitted over transport protocol such as HTTP(S).
Below are the main differences between REST and SOAP web service
WSDL (Web Services Description Language) is an XML format for describing web services and how to access them.
JAX-WS (Java API for XML Web Services) is a set of APIs for creating web services in XML format.
Ans:
JAXB (Java Architecture for XML Binding) is a Java standard that defines how Java objects are converted from and to XML. It makes reading and writing of XML via Java relatively easy.
Yes, we can send different formats such as PDF document, image or other binary file with soap messages as an attachment. Messages send using the binary data. SOAP messages is attached with MIME extensions that come in multipart/related.
An example:
MIME-Version: 1.0
Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml;
start="<claim061400a.xml@ javahungry.com>"
Content-Description: This is the optional message description.
<?xml version='1.0' ?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<theSignedForm href="cid:claim061400a.tiff@javahungry.com"/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: binary
Content-ID: <claim061400a.tiff@javahungry.com>
...binary TIFF image...
--MIME_boundary—
MTOM (Message Transmission Optimization Mechanism) is a mechanism for transmitting large binary attachments with SOAP messages as raw bytes, allowing for smaller messages.
XOP (XML-binary Optimized Packaging) is a mechanism defined for the serialization of XML Information Sets that contain binary data, as well as deserialization back into the XML Information Set.
SOAP envelop element is the root element of a SOAP message which defines the XML document as a SOAP message.
An example:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
Message information
Ans:
SOAP namespace defines the Envelope as a SOAP Envelope.
An example:
xmlns:soap=http://www.w3.org/2001/12/soap-envelope
SOAP encoding is a method for structuring the request which is suggested within the SOAP specification, known as the SOAP serialization.
SOAP encodingStyle defines the serialization rules used in a SOAP message. This attribute may appear on any element, and is scoped to that element's contents and all child elements not themselves containing such an attribute. There is no default encoding defined for a SOAP message.
An example:
SOAP-ENV:encodingStyle="http://www.w3.org/2001/12/soap-encoding"
The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files (JAX-WS portable artifacts) for web service client to access the published web services: https://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html
The wsgen tool is used to parse an existing web service implementation class and generates required files (JAX-WS portable artifacts) for web service deployment: http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsgen.html
SOAPUI tool for SOAP WS: http://www.soapui.org/
A resource is a unique URL with representation of an object which we can get contents via GET and modify via PUT, POST, DELETE.
It is not possibly, because GET can’t change a resource.
Need to use PUT when can update a resource completely through a specific resource. For example, if know that an article resides at http://javahungry.blogspot.com/article/123, can PUT a new resource representation of this article through a PUT on this URL. If do not know the actual resource location for instance, when add a new article, can use POST.
PUT is idempotent, while POST is not. It means if use PUT an object twice, it has no effect.
WADL (Web Application Description Language) is a XML description of a deployed RESTful web application.
Jersey, Restlet, EasyRest, etc.
Restlet is a lightweight, comprehensive, open source RESTful web API framework for the Java platform.
It has advantages such as
Jersey is open source framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation. It has advantages such as
RESTeasy is a JBoss project, which implements of the JAX-RS specification. It has benefits such as
Firefox “poster” plugin for RESTFUL services. https://addons.mozilla.org/en-us/firefox/addon/poster/
@Path annotation binds URI pattern to a Java method.
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
@Path("/persons")
public class PersonRestService {
@GET
public Response getPerson() {
return Response.status(200).entity("getPerson is called").build();
}
@GET
@Path("/vip")
public Response getPersonVIP() {
return Response.status(200).entity("getPersonVIP is called").build();
}
}
On calling URI: “/persons” result: getPerson is called
On calling URI: “/persons/vip” result: getPersonVIP is called
@PathParam annotation injects the value of URI parameter that defined in @Path expression.
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/persons")
public class PersonRestService {
@GET
@Path("{id}")
public Response getPersonById(@PathParam("id") String id) {
return Response.status(200).entity("getPersonById is called, id : " + id).build();
}
}
On calling URI: “/persons/1” result: getPersonById is called, id : 1
@QueryParam annotation injects URI query parameter into Java method.
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
@Path("/persons")
public class PersonService {
@GET
@Path("/query")
public Response getPersons(
@QueryParam("from") int from,
@QueryParam("to") int to,
@QueryParam("orderBy") List<String> orderBy) {
return Response
.status(200)
.entity("getPersons is called, from : " + from + ", to : " + to
+ ", orderBy" + orderBy.toString()).build();
}
}
@MatrixParam are a set of “name=value” in URI path.
import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/books")
public class BookService {
@GET
@Path("{year}")
public Response getBooks(@PathParam("year") String year,
@MatrixParam("author") String author,
@MatrixParam("country") String country) {
return Response
.status(200)
.entity("getBooks is called, year : " + year
+ ", author : " + author + ", country : " + country)
.build();
}
}
@FormParam bind HTML form parameters value to a Java method.
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
@Path("/persons")
public class PersonService {
@POST
@Path("/add")
public Response addPerson(
@FormParam("name") String name,
@FormParam("age") int age) {
return Response.status(200)
.entity("addPerson is called, name : " + name + ", age : " + age)
.build();
}
}
inject directly with @HeaderParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.core.Response;
@Path("/persons")
public class PersonService {
@GET
@Path("/get")
public Response getPerson(
@HeaderParam("person-agent") String personAgent) {
return Response.status(200)
.entity("getPerson is called, personAgent : " + personAgent)
.build();
}
}
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
@Path("/persons")
public class PersonService {
@GET
@Path("/get")
public Response getPerson(@Context HttpHeaders headers) {
String personAgent = headers.getRequestHeader("person-agent").get(0);
return Response.status(200)
.entity("getPerson is called, personAgent : " + personAgent)
.build();
}
}
import java.io.File;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@Path("/image")
public class ImageService {
private static final String FILE_PATH = "c:\\my.png";
@GET
@Path("/get")
@Produces("image/png")
public Response getFile() {
File file = new File(FILE_PATH);
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition",
"attachment; filename=image_from_server.png");
return response.build();
}
}
The initiation of XML in this field is the advancement that provides web service a single language to communicate in between the RPCs, web services and their directories.
One example of web services is IBM Web Services browser. You can get it from IBM Alphaworks site. This browser shows various demos related to web services. Basically web services can be used with the help of SOAP, WSDL, and UDDI . All these, provide a plug-and-play interface for using web services such as stock-quote service, a traffic-report service, weather service etc.
It is basically set of various protocols that can be used to explore and execute web services. The entire stack has four layers i.e. Service Transport, XML Messaging, Service Description and Service Discovery.
The Service Transport layer transfer messages between different applications, such as HTTP, SMTP, FTP, and Blocks Extensible Exchange Protocol (BEEP). The XML Messaging layer encodes messages in XML format so that messages can be understood at each end, such as XML-RPC and SOAP. The Service Description layer describes the user interface to a web service, such as WSDL. The Service Discovery layer centralizes services to a common registry and offer simple publish functionality, such as UDDI.
It is a protocol that makes use of XML messages to do Remote Procedure Calls.
It means Web Services Description Language. It is basically the service description layer in the web service protocol stock. The Service Description layer describes the user interface to a web service.
The security level for web services should be more than that of what we say Secure Socket Layer (SSL). This level of security can be only achieved from Entrust Secure Transaction Platform. Web services need this level of security to ensure reliable transactions and secure confidential information .
As implies from its name, these services are the foundation or basics of integration, authentication, authorization, digital signatures and encryption processes.
Entrust Identification Service comes from the Entrust Security Transaction Platform. This platform allows companies to control the identities that are trusted to perform transactions for Web services transactions.
UDDI stands for Universal, Description, Discovery, and Integration. It is the discovery layer in the web services protocol stack.
This service verifies entities that attempt to access a web service. For Example, the authentication service, the Entitlements Service ensures security in business operations.
As its name implies, it deals with security and confidentiality. This service encrypts data to ensure that only concerned parties can access the data.
It means Public-Key Infrastructure.
Ans:
I have used SoapUI for SOAP WS and Firefox poster plugin for RESTFul Services.
SOA is a design and architecture to implement other services. SOA can be easily implemented using various protocols such as HTTP, HTTPS, JMS, SMTP, RMI, IIOP, RPC etc. While Web service, itself is an implemented technology. In fact one can implement SOA using the web service.
We can develop SOAP based web service with two different types of approaches such as contract-first and contract-last. In the first approach, the contract is defined first and then the classes are derived from the contract while in the later one, the classes are defined first and then the contract is derived from these classes.
In my point of view, the first approach that is the contract-first approach is more feasible as compared to the second one but still it depends on other factors too.
No, you don’t need to install any special application to access web service. You can access web service from any application that supports XML based object request and response.
The implementations I know are Apache SOAP, JAX-WS Reference Implementation, JAX-RS Reference Implementation, Metro, Apache CXF, MS.NET and Java 6.
JavaScript XmlHttpRequest object is required to access web service via browsers. The browsers that support this object are Internet Explorer, Safari and Mozilla-based browsers like FireFox.
REST stands for Representational State Transfer. REST itself is not a standard, while it uses various standards such as HTTP, URL, XML/HTML/GIF/JPEG (Resource Representations) and text/xml, text/html, image/gif, image/jpeg, etc (MIME Types).
To provide an API to the users, one can easily do this with an “open table”. All you need to do is to write open table which is basically an XML schema that point to a web service.
Web service is integrated with three protocols such as HTTP/POST, HTTP/GET, and SOAP. It provides three different communication channels to clients. Client can choose any communication method as per requirements.
Web services are contemplated as self-documenting because they provide entire information regarding the available methods and parameters used for XML based standard, known as WSDL. One can also provide more information to explain web services via their own WebService and WebMethod attributes.
ASP.NET web services are used when one need to implement three tier architecture in a web service. It allows handy ways to use middle tier components through internet. The main advantage of .NET Web services is that they are capable enough to communicate across firewalls because they use SOAP as transport protocol.
The increasing ratio of distributed applications has raised demand for distributed technologies. It allows segmenting of application units and transferring them to different computers on different networks.
Web services transfer/receive messages to/from application respectively, via HTTP protocol. It uses XML to encode data.
CORBA and DCOM transfer/receive messages to/from application respectively, via non-standard protocols such as IIOP and RPC.
The biggest advantage of web service is that is supported by wide variety of platforms. Moreover, in near future, web services may spread its boundary and enhance new methods that will provide ease to clients. The enhancement will not affect the clients, even if they offer old methods and parameters.
The standards used in web services are WSDL (used to create interface definition), SOAP (used to structure data), HTTP (communication channels), DISCO (used to create discovery documents) and UDDI (used to create business registries).
DISCO means discovery. It groups the list of interrelated web services. The organization that provides web services, issues a DISCO file on its server and that file contains the links of all the provided web services. This standard is good when client knows the company already. Also it can be used within a local network as well.
UDDI (Universal Description, Discovery, and Integration) provides consolidated directory for web services on the internet. Clients use UDDI to find web services as per their business needs. It basically hosts the web services from various companies. In order to share web services, you need to publish it in UDDI.
.Net web services uses XML-based standards to transfer/receive information. Thus, .NET web services can only works with data types known by XML schema standard. Like FileSteam, Eventlog etc. are not recognized by the XML schema standards and hence, not supported in web services.
ASP.NET uses a test page routinely, when one calls for the URL of .asmx file in any browser. This page shows complete information regarding web services.
Since we know that web services are constructed on XML standards. Therefore, clients need to have complete understanding of XML-based messages to interchange messages. Clients can communicate with web services through .NET framework that offers proxy mechanisms. These proxy mechanisms have detailed information regarding data sharing within web services that can be easily used by the clients.
The two Microsoft solutions for distributed applications are .NET Web Services and .NET Remoting.
As far as protocol is concerned, .NET Web Service uses HTTP, while, .NET Remoting uses any protocol i.e. TCP/HTTP/SMTP. When it comes to performance, .NET Remoting is comparatively, faster than.NET Web Service. Also, as .NET Web Services are hosted via IIS, therefore, it is far more reliable than the .NET Remoting.
The components that need to be published during a web service deployment are Web Application Directory, Webservice.asmx File, Webservice.Disco File, Web.Config File and Bin Directory.
First of all a web reference to the web service is created by the client in his application. Then a proxy class is generated. After that an object of the proxy class is created and at last, the web service is accessed via that proxy object.
To implement web services in .NET, HTTP handlers are used that interrupt requests to .asmx files.
Response Caching is useless or incompetent when method accepts extensive amount of values because caching means to store lot of information. Also, if the method depends on external source of information, and that are not provided within the parameters then such methods are bypassed.
One can use Data Caching (System.Web.Caching.Cach) instead of Response Caching.
These methods are less secure and inhibit users to pass structures and objects as arguments. Also, it doesn’t allow users to pass ByRef arguments.
To access a class as a web service, one should inherit the class from the System.Web.Services.WebService class and qualify the class with the WebService attribute.
To access web service class method via internet, one should qualify a method with the WebMethod attribute.
A SOAP message is consists of SOAP Envelope, SOAP Headers, and SOAP Body.
There are two types of web services in total i.e. SOAP based web service and RESTful web service.
This question is already mentioned earlier.
The RESTful web services contains no contract or WSDL file.
The RESTFul web services are simple to implement and test. It supports various data formats such as XML, JSON etc.
Java webservices is developed to build and deploy basic web service on JAVA platform.
To create a web services, there are two approaches that are adopted
JAXP is a JAVA API for XML processing that enables application to write, read, manipulate and transform XML data. Similarly, to perform other various function there are other Java API’s as well like JAX-RPC, JAXM, JAXR, JAXB, etc.
JAXB binding framework is available in three Java Packages
Marshalling is the process of converting XML document into Java readable form while UnMarshalling is the reverse process of Marshalling. Let see how Java unmarshals an XML document and then marshals it back
JAXBContext jc= JAXBContext.newInstance (“com.acme.foo”);
// unmarshal from foo.xml
Unmarshaller u = jc.createUnmarshaller () ;
FooObject fooObj=
(FooObject)u.unmarshal (new File (“foo.xml”) );
// marshal to sytem.out
Marshaller m = jc.createMarshaller ();
m.marshal (fooObj, System.out);
Ans:
By default, the Marshaller will use “UTF-8” if jaxb.encoding property is not declared.
There are two types of JAXB client validation that a JAXB can perform
JAXB schema binding compiler is placed in the <JWSDP_Home>/jaxb/bin directory. In this directory, there are two scripts, xjc.sh (Solaris/Linux) and xjc.bat (Windows).
In some cases, you are required to customize the default binding like
XML can be used to sign any arbitrary data whether it is a binary or XML. The data is recognized via URIs in one or more reference elements. It is described in one or more forms, like detached, enveloping or enveloped.
Stax stands for Streaming API for XML; it is an API to read and write XML documents, originating from the JAVA programming language.
The usual XML APIs includes
XWS security is based on securing web services build on JAX-RPC and on stand-alone application based on SAAJ. For securing JAX-RPC application, options that XWS security provides are
Digital signature API is
JAXR is the JAVA programming APIs for Java platform application to access and programmatically interact with various kinds of meta-data registries.
JAXR architecture is consists of a JAXR client and JAXR provider.
There are two types of messaging models for JAXM synchronous and asynchronous