Web
1. Compare
and contrast web applications with web services, indicating the need for web
services
Web Service
W3C (World Wide Web Consortium)
describes web service as a system of software allowing different machines to
interact with each other through network. Web services achieve this task with
the help of XML, SOAP, WSDL and UDDI open standards.
XML: The full form of XML is ‘Extensible Markup Language’
which is used to share data on the web and in universal format.
SOAP: Standing for ‘Simple Object Access Protocol’ which is an
application communication protocol that sends and receives messages through XML
format. It is one of the best ways to communicate between applications over
HTTP which is supported by all browsers and servers.
WSDL: Written in XML, WSDL stands for Web Services Description
Language and is used to describe web service. WSDL comprises three parts such
as Definitions (usually expressed in XML including both data type definitions),
Operations and Service bindings. Operations denote actions for the messages
supported by a Web service.
There are three types of operations:
1. One way
2. Request response
3. Notification
Service
bindings: Service bindings is a
connecting to the port.
UDDI: Universal Description, Discovery, and Integration (UDDI)
provides the description of a set of services supporting the depiction and
discovery of businesses, organizations, and other Web Services providers. It is
based on common set of industry standards, including HTTP, XML, XML Schema, and
SOAP.
Web Application
An application that the users access
over the internet is called a web application.
Generally, any software that is accessed through a client web browser could be
called a web application.
What is
client?
So what is a client? A ‘client’ can be
referred to the program that the person use to run the application in the
client-server environment. The client-server environment refers to multiple
computers sharing information such as entering info into a database. Here the
“client” is the application that is used to enter the info, while the “server”
is the application that is used to store the information.
Web Services
vs Web Applications
- Web Services can be used to
transfer data between Web Applications.
- Web Services can be accessed from
any languages or platform.
- A Web Application is meant for
humans to read, while a Web Service is meant for computers to read.
- Web Application is a complete
Application with a Graphical User Interface (GUI), however, web services
do not necessarily have a user interface since it is used as a component
in an application.
- Web Application can be access
through browsers.
2. Discuss
what WSDL is and the use of it in the context of web services
Web
Services Description Language (WSDL) is a format for describing a Web Services
interface. It is a way to describe services and how they should be bound to
specific network addresses. WSDL has three parts:
- Definitions
- Operations
- Service bindings
Definitions
are generally expressed in XML and include both data type definitions and
message definitions that use the data type definitions. These definitions are
usually based upon some agreed upon XML vocabulary. This agreement could be
within an organization or between organizations. Vocabularies within an
organization could be designed specifically for that organization. They may or
may not be based on some industry-wide vocabulary. If data type and message
definitions need to be used between organizations, then most likely an
industry-wide vocabulary will be used. For more on XML vocabularies,
XML,
however, is not necessary required for definitions. The OMG Interface Definition
Language (IDL), for example, could be used instead of XML. If a different
definitional format were used, senders and receivers would need to agree on the
format as well as the vocabulary. Nevertheless, over time, XML-based
vocabularies and messages are likely to dominate. XML
Namespaces
are used to ensure uniqueness of the XML element names in the definitions,
operations, and service bindings.
Operations
describe actions for the messages supported by a Web service. There are four
types of operations:
- One-way:
Messages sent without a reply required
- Request/response:
The sender sends a message and the received sends a reply.
- Solicit
response: A request for a response. (The specific definition for this
action is pending.)
- Notification:
Messages sent to multiple receivers. (The specific definition for this
action is pending.)
Operations
are grouped into port types. Port types define a set of operations supported by
the Web service.
Service
bindings connect port types to a port. A port is defined by associating a
network address with a port type. A collection of ports defines a service. This
binding is commonly created using SOAP, but other forms may be used. These
other forms could include CORBA Internet Inter-ORB Protocol (IIOP), DCOM, .NET,
Java Message Service (JMS), or WebSphere MQ to name a few.
3.
Explain
the fundamental properties of a WSDL document and the use of WSDL document in
web services and client development
WSDL
is an XML-based file which basically tells the client application what the web
service does. It is known as the Web Services Description Language(WSDL).
In
this tutorial, we are going to focus on the last point which is the most
important part of web services, and that is the WSDL or the Web services
description language.
The
WSDL file is used to describe in a nutshell what the web service does and gives
the client all the information required to connect to the web service and use
all the functionality provided by the web service.
In
this tutorial, you will learn-
- Structure of a WSDL Document
- WSDL Elements
- Why WSDL
- WSDL Message Part
- Port Type Binding
- Creating WSDL File
- Publishing the Web Service
Example
Structure of a WSDL Document
A
WSDL document is used to describe a web service. This description is required,
so that client applications are able to understand what the web service
actually does.
- The WSDL file
contains the location of the web service and
- The methods
which are exposed by the web service.
The
WSDL file itself can look very complex to any user, but it contains all the
necessary information that any client application would require to use the
relevant web service.
Below
is the general structure of a WSDL file
- Definition
- TargetNamespace
- DataTypes
- Messages
- Porttype
- Bindings
- service
One
key thing to note here is that definition of messages, which is what is passed
by the SOAP protocol is actually defined in the WSDL document.
The
WSDL document actually tells a client application what are the types of SOAP
messages which are sent and accepted by the Web service.
In
other words, the WSDL is just like a postcard which has the address of a
particular location. The address provides the details of the person who
delivered the postcard. Hence, in the same way, the WSDL file is the postcard,
which has the address of the web service which can deliver all the
functionality that the client wants.
WSDL Elements
The
WSDL file contains the following main parts
1.
The
<types> tag is used to define all the complex datatypes, which
will be used in the message exchanged between the client application and the
web service. This is an important aspect of the client application, because if
the web service works with a complex data type, then the client application
should know how to process the complex data type. Data types such as float,
numbers, and strings are all simple data types, but there could be structured
data types which may be provided by the web service.
For
example, there could be a data type called EmployeeDataType which could have 2
elements called "EmployeeName" of type string and
"EmployeeID" of type number or integer. Together they form a data
structure which then becomes a complex data type.
2.
The
<messages> tag is used to define the message which is exchanged
between the client application and the web server. These messages will explain
the input and output operations which can be performed by the web service. An
example of a message can be a message which accepts the EmployeeID of an
employee, and the output message can be the name of the employee based on the
EmpoyeeID provided.
3.
The
<portType> tag is used to encapsulate every input and output
message into one logical operation. So there could be an operation called
"GetEmployee" which combines the input message of accepting the
EmployeeID from a client application and then sending the EmployeeName as the
output message.
4.
The
<binding> tag is used to bind the operation to the particular port
type. This is so that when the client application calls the relevant port type,
it will then be able to access the operations which are bound to this port
type. Port types are just like interfaces. So if a client application needs to
use a web service they need to use the binding information to ensure that they
can connect to the interface provided by that web service.
5.
The
<service> tag is a name given to the web service itself.
Initially, when a client application makes a call to the web service, it will
do by calling the name of the web service. For example, a web service can be
located at an address such as http://localhost/Guru99/Tutorial.asmx .
The service tag will actually have the URL defined as http://localhost/Guru99/Tutorial.asmx,
which will actually tell the client application that there is a web service
available at this location.
Why WSDL
A
web service is an important component in building modern day web applications.
Their main purpose is to allow multiple applications built on various
programming languages to talk to each other. For instance, we can have a .Net
web application talks to a Java application
via a Web service.
A
web service has the following key features
- It is built
using the XML programming language. Almost all modern day technologies
such as .Net and Java have corresponding commands that have the ability to
work with XML. Hence, XML was taken as the most appropriate language for
building web services.
- Web services
communicate over HTTP. HTTP is a protocol used by all web-based
applications. Hence, it just made sense to ensure that Web services also
had the ability to work over the HTTP protocol.
- Web services
conform to a particular language specification. This specification is set
by the W3C, which is the governing body for all web standards.
- Web services
have a description language known as WSDL, which is used to describe the
web service.
The
WSDL file is written in plain old XML. The reason that it is in XML is so that
the file can be read by any programming language.
So
if the client application was written in .Net, it would understand the XML
file. Similarly, if the client application was written in the Java programming
language then also it would be able to interpret the WSDL file.
The
WSDL file is what binds everything together. From the above diagram, you can
see that you can create a web service in the .Net language.
So
this is where the service gets implemented. If you did not have the WSDL file
and wanted a Java class to consume the web service, you would need a lot of
coding effort to achieve this.
But
now with the WSDL file which is in XML, which can be understood by any programming
language, you can now easily have a Java class consume the .Net web service.
Hence, the amount of coding effort is greatly reduced.
4.
Discuss
the structure of the WSDL document, explaining the elements in WSDL
A
WSDL document has a definitions element that contains the other five elements,
types, message, portType, binding and service. The following sections describe
the features of the generated client code.
WSDL
supports the XML Schemas specification (XSD) as its type system.
definitions
Contains the definition of one or more
services. JDeveloper generates the following attribute declarations for this
section:
·
name is optional.
·
targetNamespace is the logical namespace for
information about this service. WSDL documents can import other WSDL documents,
and setting targetNamespace to a unique value ensures that the namespaces do
not clash.
·
xmlns is the default namespace of the WSDL
document, and it is set to http://schemas.xmlsoap.org/wsdl/.
·
All
the WSDL elements, such as <definitions>, <types> and <message> reside in this namespace.
·
xmlns:xsd and xmlns:soap are standard namespace definitions
that are used for specifying SOAP-specific information as well as data types.
·
xmlns:tns stands for this namespace.
·
xmlns:ns1 is set to the value of the schema targetNamespace, in the <types> section.
types
Provides information about any complex
data types used in the WSDL document. When simple types are used the document
does not need to have a types section.
message
An abstract definition of the data
being communicated. In the example, the message contains just one part,
response, which is of type string, where string is defined by the XML Schema.
operation
An abstract description of the action
supported by the service.
portType
An abstract set of operations supported
by one or more endpoints.
binding
Describes how the operation is invoked
by specifying concrete protocol and data format specifications for the
operations and messages.
port
Specifies a single endpoint as an
address for the binding, thus defining a single communication endpoint.
service
Specifies the port address(es) of the
binding. The service is a collection of network endpoints or ports.
5. Compare
the PortType and operation elements in WSDL with the java equivalences
portType (Analogs to Java interface)
- PortType is an
abstraction part of WSDL.
- An abstract set
of operations supported by one or more endpoints.
A single Web service can support a number of different protocols. The structure of the data depends on the protocol that you use to invoke the Web service. Because of this, you need a way to map from the operations to the endpoints from which they can be accessed. The portType element takes care of this mapping.
6. Compare
and contrast the binding and service elements in WSDL
binding
- Binding is an
concrete part of WSDL.
- Describes how
the operation is invoked by specifying concrete protocol and data format
specifications for the operations and messages.
- bindings are three types
1.
SOAP Binding:
SOAP binding allows either document or rpc style with either encoding or literal. Encoding indicates how a data value should be encoded in an XML format (These rules specify how "something" is encoded/serialized to XML and then later decoded/de-serialized from XML back to "something"). Literal means that the data is serialized according to a schema (this is just plain XML data). With transportation type http, jms, smtp...
SOAP binding allows either document or rpc style with either encoding or literal. Encoding indicates how a data value should be encoded in an XML format (These rules specify how "something" is encoded/serialized to XML and then later decoded/de-serialized from XML back to "something"). Literal means that the data is serialized according to a schema (this is just plain XML data). With transportation type http, jms, smtp...
2.
HTTP GET & POST binding:
WSDL includes a binding for HTTP 1.1's GET and POST verbs in order to describe the interaction between a Web Browser and a web site.
WSDL includes a binding for HTTP 1.1's GET and POST verbs in order to describe the interaction between a Web Browser and a web site.
3.
MIME binding: WSDL includes a way to bind abstract types to concrete
messages in some MIME format.
7. Explain
how SOAP is used with HTTP
SOAP ( Simple Object Access Protocol) is a message protocol
that allows distributed elements of an application to communicate. SOAP can be
carried over a variety of lower-level protocols, including the web-related
Hypertext Transfer Protocol (HTTP).
SOAP defines a header structure
that identifies the actions that various SOAP nodes are expected to take on the
message, in addition to a payload structure for carrying information. The
concept of routing a message through a string of nodes that perform different
functions is how SOAP supports things like addressing, security and
format-independence. Essentially, the headers identify roles, which in turn
provide the SOA features which SOAP then routes to. Stringing messages through
a sequence of steps is uncommon in today’s microservice-centric development
environments.
8. Discuss
how SOAP can be used for functional oriented communication?
SOAP Communication Model.
All
communication by SOAP is done via the HTTP protocol. Prior to SOAP, a lot of
web services used the standard RPC (Remote Procedure Call) style for
communication. This was the simplest type of communication, but it had a lot of
limitations.
Let's
consider the below diagram to see how this communication works. In this
example, let's assume the server hosts a web service which provided 2 methods
as
- GetEmployee - This would
get all Employee details
- SetEmployee – This would
set the value of the details like employees dept, salary, etc.
accordingly.
In
the normal RPC style communication, the client would just call the methods in
its request and send the required parameters to the server, and the server
would then send the desired response.
The
above communication model has the below serious limitations
1.
Not
Language Independent
– The server hosting the methods would be in a particular programming language
and normally the calls to the server would be in that programming language
only.
2.
Not
the standard protocol –
When a call is made to the remote procedure, the call is not carried out via
the standard protocol. This was an issue since mostly all communication over
the web had to be done via the HTTP protocol.
3.
Firewalls
– Since RPC calls do
not go via the normal protocol, separate ports need to be open on the server to
allow the client to communicate with the server. Normally all firewalls would
block this sort of traffic, and a lot of configuration was generally required
to ensure that this sort of communication between the client and the server
would work.
To
overcome all of the limitations cited above, SOAP would then use the below
communication model
1.
The
client would format the information regarding the procedure call and any
arguments into a SOAP message and sends it to the server as part of an HTTP
request. This process of encapsulating the data into a SOAP message was known
as Marshalling.
2.
The
server would then unwrap the message sent by the client, see what the client
requested for and then send the appropriate response back to the client as a
SOAP message. The practice of unwrapping a request sent by the client is known
as Demarshalling.
9. Explain
the structure of SOAP message in message oriented communication, indicating the
elements used
SOAP
messaging
A SOAP message may need to be transmitted together with attachments of various sorts, ranging from facsimile images of legal documents to engineering drawings. Such data are often in some binary format. For example, most images on the Internet are transmitted using either GIF or JPEG data formats.
A SOAP message may need to be transmitted together with attachments of various sorts, ranging from facsimile images of legal documents to engineering drawings. Such data are often in some binary format. For example, most images on the Internet are transmitted using either GIF or JPEG data formats.
- A required
Envelope element that identifies the XML document as a SOAP message
- An optional
Header element that contains header information
- A required Body
element that contains call and response information
- An optional
Fault element that provides information about errors that occurred while processing
the message
A SOAP message package contains a primary SOAP message. It
may also contain additional entities that are not lexically within the SOAP
message but are related in some manner. These entities may contain data in
formats other than XML. The primary SOAP message in a message package may
reference the additional entities. Such additional entities are often
informally referred to as 'attachments.'"
10.
Discuss the importance of the SOAP
attachments, explaining the MIME header
What is MIME?
The MIME stands for Multi-Purpose Internet Mail Extensions.
As the name indicates, it is an extension to the Internet email protocol that
allows it’s users to exchange different kinds of data files over the Internet
such as images, audio, and video. The MIME is required if text in character
sets other than ASCII. Virtually all human-written Internet email and a fairly
large proportion of automated email is transmitted via SMTP in MIME format.
Actually, MIME was designed mainly for SMTP, but the content types defined by
MIME standards are important also in communication protocols outside of email,
such as HTTP. In 1991, Nathan Borenstein of Bellcore proposed to the IETF that
SMTP be extended so that Internet (but mainly Web) clients and servers could
recognize and handle other kinds of data than ASCII text. As a result, new file
types were added to “mail” as a supported Internet Protocol file type.
MIME headers
Now, let’s see the MIME headers. There
are many sub parts come under MIME headers. Let’s see each in detail.
1) MIME-Version
2) Content-Type
3) Content-Disposition
4) Content-Transfer-Encoding
Securing SOAP With Attachments
Attachments
may be associated with SOAP messages, as outlined in SOAP Messages with
Attachments [SwA]. This profile defines how such attachments may be
secured for integrity and confidentiality using the OASIS Web Services
Security: SOAP Message Security standard. This does not preclude using other
techniques. The requirements in this profile only apply when securing SwA
attachments explicitly according to this profile.
This
profile considers all attachments as opaque whether they are XML or some other
content type. It is the sole responsibility of the application to perform
further interpretation of attachments, including the ability to sign or encrypt
portions of those attachments.
11.
Identify different set of
frameworks/libraries for SOAP web service development, in different
environments (Java, .Net, PHP, etc...)
Name
|
Platform
|
Messaging Model(Destination)
|
Specifications
|
Protocols
|
Java/C++
|
Client/Server
|
WS-ReliableMessaging, WS-Coordination, WS-Security,
WS-AtomicTransaction, WS-Addressing
|
||
Java
|
Client/Server/ Asyn Support
|
WS-ReliableMessaging, WS-Security, WS-AtomicTransaction,
WS-Addressing, MTOM, WS-Policy, WS-MetadataExchange
|
||
Java
|
Client/Server/ Asyn Support
|
WS-ReliableMessaging, WS-Security, WS-Addressing, MTOM,
WS-Policy, WS-SecureConversation, WS-SecurityPolicy, WS-Trust
|
||
Client/Server
|
An open source MVC web application framework
|
|||
C and C++
|
Client/Server Duplex/Async
|
WS-Addressing, WS-Discovery, WS-Policy,
WS-ReliableMessaging, WS-Security, WS-SecurityPolicy
|
||
Java
|
Client/Server
|
WS-Addressing, WS-Security, ???
|
||
GAE/Java
|
Client/Server/Asyn Support
|
End-to-End Java framework for Google App Engine including comprehensive Data
Authorization model, a powerful RESTful engine, and out-of-the-box UI views.
|
||
Java
|
Client/Server
|
Project Jersey is the production-ready reference
implementation for the JAX-RS specification by Oracle (Originally Sun)
|
||
C#, VB.NET
|
Client/Server
|
WS-Addressing, WS-MetadataExchange, WS-Security,
WS-Policy, WS-SecurityPolicy, WS-Trust, WS-SecureConversation,
WS-ReliableMessaging, WS-Coordination, WS-AtomicTransaction
|
||
Java
|
Client/Server
|
WS-Addressing, WS-ReliableMessaging, WS-Coordination,
WS-AtomicTransaction, WS-Security, WS-Security Policy, WS-Trust,
WS-SecureConversation, WS-Policy, WS-MetadataExchange
|
||
Java
|
Client
|
???
|
||
.NET
|
Client/Server/Asyn support
|
WS-Addressing, WS-MetadataExchange, WS-Security,
WS-Policy, WS-SecurityPolicy, WS-Trust, WS-SecureConversation,
WS-ReliableMessaging, WS-Coordination, WS-AtomicTransaction,WS-Discovery
|
||
PHP
|
Client/Server
|
SOAP MTOM, WS-Addressing, WS-Security, WS-SecurityPolicy,
WS-Secure Conversation, WS-ReliableMessaging
|
||
XFire
became Apache CXF
|
Java
|
Client/Server
|
WS-Addressing, WS-Security
|
|
Java
|
Server ?
|
??
|
||
Client/Server
|
Web application Components helping build MVC project.
|
|||
Client/Server
|
Open source, object-oriented, component-based MVC
|
|||
Client/Server
|
a free, BSD licensed, open-source web framework
|
|||
Client/Server
|
PHP web application framework
|
|||
Client/Server
|
Web application framework implemented in PHP
|
Copyright From Wikipedia, the free encyclopedia.
12.
Explain the annotations in
JAX-WS, providing examples of their use
JAX-WS annotations
1.1 @WebService
This JAX-WS annotation can be used in 2 ways. If we are
annotating this over a class, it means that we are trying to mark the class as
the implementing the Web Service, in other words Service Implementation Bean
(SIB). Or we are marking this over an interface, it means that we are defining
a Web Service Interface (SEI), in other words Service Endpoint Interface.Now lets see the java program demonstrating both of the mentioned ways:
WSAnnotationWebServiceI.java
package com.javacodegeeks.examples.jaxWsAnnotations.webservice;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 WSAnnotationWebServiceI { @WebMethod float celsiusToFarhenheit(float celsius);} |
@WebService annotation. And here it is used to define SEI. Regarding
the other annotations used in the above program, we shall see their description
a little ahead.WsAnnotationsWebServiceImpl.java
package com.javacodegeeks.examples.jaxWsAnnotations.webservice;import javax.jws.WebService;@WebService(endpointInterface="com.javacodegeeks.examples.jaxWsAnnotations.webservice.WSAnnotationWebServiceI")public class WsAnnotationsWebServiceImpl implements WSAnnotationWebServiceI { @Override public float celsiusToFarhenheit(float celsius) { return ((celsius - 32)*5)/9; }} |
endpointInterface along with the @WebService annotation. And here it is used to define SIB. endpointInterface
optional element describes the SEI that the said SIB is implementing.While implementing a web service as in above example, it is not mandatory for
WsAnnotationsWebServiceImpl to implement WSAnnotationWebServiceI, this just serves as a check. Also, it is not mandatory to
use an SEI, however, as a basic design principle “We should program to
interface”, hence we have adapted this methodology in above program.Other optional elements to
@WebService
can be like wsdlLocation that defines location of pre-defined wsdl defining the web
service, name that defines name of the web service etc.
1.2 @SOAPBinding
Demonstration of @SOAPBinding JAX-WS annotation has already been shown in first program
in 1.1. This
annotation is used to specify the SOAP messaging style which
can either be RPC or DOCUMENT. This style represents the encoding style of message sent
to and fro while using the web service.With
RPC style a web service is capable of only using simple data
types like integer or string. However, DOCUMENT style is capable of richer data types for a class let’s say
Person, which can have attributes like String
name, Address address
etc.Document style indicates that in the underlying web service,
underlying message shall contain full XML documents, whereas in the RPC
style, the underlying message contains parameters and return values in request
and response message respectively. By default the style is Document.The other important optional attribute is
use. It
represents the formatting style of the web service message. Its value can
either be literal or encoded.
1.3 @WebMethod
@WebMethod JAX-WS annotation can be applied over a method only. This specified
that the method represents a web service operation. For its demonstration,
please refer to first program in 1.1.
1.4 @WebResult
To understand this JAX-WS annotation, let’s write SEI &
SIB again:package com.javacodegeeks.examples.jaxWsAnnotations.webresult;import javax.jws.WebMethod;import javax.jws.WebResult;import javax.jws.WebService;import javax.jws.soap.SOAPBinding;import javax.jws.soap.SOAPBinding.Style;@WebService@SOAPBinding(style
= Style.RPC)public interface WSAnnotationsWebResultI { @WebMethod @WebResult(partName="farhenheitResponse") float celsiusToFarhenheit(float celsius);} |
package com.javacodegeeks.examples.jaxWsAnnotations.webresult;import javax.jws.WebService;@WebService(endpointInterface="com.javacodegeeks.examples.jaxWsAnnotations.webresult.WSAnnotationsWebResultI")public class WSAnnotationsWebResultImpl implements WSAnnotationsWebResultI { @Override public float celsiusToFarhenheit(float celsius) { return ((celsius - 32)*5)/9; }} |
WSPublisher.java
package com.javacodegeeks.examples.jaxWsAnnotations.webresult;import javax.xml.ws.Endpoint;public class WSPublisher { public static void main(String[] args) { }} |
http://127.0.0.1:9999/ctf?wsdl) would be like:Refer to the highlighted line in above wsdl, the
part name has
been changed to “farhenheitResponse” as was defined using @WebResult. What interest here is that @WebResult
can be used to determine what the generated WSDL shall look like.<definitions xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="WSAnnotationsWebResultImplService"> <types /> <message name="celsiusToFarhenheit"> <part name="arg0" type="xsd:float" /> </message> <message name="celsiusToFarhenheitResponse"> <part name="return" type="xsd:float" /> </message> <portType name="WSAnnotationsWebResultI"> <operation name="celsiusToFarhenheit"> <input wsam:Action="http://webresult.jaxWsAnnotations.examples.javacodegeeks.com/WSAnnotationsWebResultI/celsiusToFarhenheitRequest" message="tns:celsiusToFarhenheit" /> <output wsam:Action="http://webresult.jaxWsAnnotations.examples.javacodegeeks.com/WSAnnotationsWebResultI/celsiusToFarhenheitResponse" message="tns:celsiusToFarhenheitResponse" /> </operation> </portType> <binding name="WSAnnotationsWebResultImplPortBinding" type="tns:WSAnnotationsWebResultI"> style="rpc" /> <operation name="celsiusToFarhenheit"> <soap:operation soapAction="" /> <input> <soap:body use="literal" </input> <output> <soap:body use="literal" </output> </operation> </binding> <service name="WSAnnotationsWebResultImplService"> <port name="WSAnnotationsWebResultImplPort" binding="tns:WSAnnotationsWebResultImplPortBinding"> </port> </service></definitions> |
part
name has value return.Other elements to
@WebResult are WebParam.Mode that defines the direction in which parameter is flowing, targetNamespace
to define XML namespace for the parameter.
1.5 @WebServiceClient
To understand @WebServiceClient JAX-WS annotation, let us
first publish the endpoint written in 1.1 using
below program:WSPublisher.java
package com.javacodegeeks.examples.jaxWsAnnotations.webservice;import javax.xml.ws.Endpoint;public class WSPublisher
{ public static void main(String[]
args) { }} |
wsimport utility provided by Java that eases the task of writing
client for a SOAP based web service. We won’t go into much detail here about wsimport, instead let’s first save the wsdl file with name
‘ctf.wsdl’ and then write following command on the command prompt:wsimport -keep -p client ctf.wsdl
1.6 @RequestWrapper
@RequestWrapper JAX-WS annotation is used to annotate methods in the
Service Endpoint Interface with the request wrapper bean to be used at runtime.
It has 4 optional elements; className that represents the request wrapper bean name, localName that
represents element’s local name, partName that represent the part name of the wrapper part in the
generated WSDL file, and targetNamespace that represents the element’s namespace.
1.7 @ResponseWrapper
@ResponseWrapper JAX-WS annotation is used to annotate methods in the
Service Endpoint Interface with the response wrapper bean to be used at
runtime. It has 4 optional elements; className that represents the response wrapper bean name, localName that
represents element’s local name, partName that represent the part name of the wrapper part in the
generated WSDL file, and targetNamespace that represents the element’s namespace.
1.8 @Oneway
@Oneway JAX-WS annotation is applied to WebMethod which means that
method will have only input and no output. When a @Oneway
method is called, control is returned to calling method even before the actual
operation is performed. It means that nothing will escape method neither
response neither exception.
1.9 @HandlerChain
Web Services and their clients may need to access the SOAP
message for additional processing of the message request or response. A SOAP
message handler provides a mechanism for intercepting the SOAP message during
request and response.A handler at server side can be a validator. Let’s say we want to validate the temperature before the actual service method is called. To do this our validator class shall implement interface
SOAPHandlerNext we shall implement SOAP handler xml file that may also contain sequence of handlers.
After this we shall configure
@HandlerChain
JAX-WS annotation in SEI:
13.
Discuss how a web service can be tested using
different approaches (using a dummy client or a dedicated tool, etc...)
What is Web Service Testing?
Web
Services Testing is testing of Web services and its Protocols like SOAP &
REST. To test a Webservice you can
1.
Test
Manually
2.
Create
your own Automation Code
3.
Use
an off-the shelf automation tool like SoapUI.
WebService
Testing involves following steps -
1.
Understand
the WSDL file
2.
Determine
the operations that particular web service provides
3.
Determine
the XML request format which we need to send
4.
Determine
the response XML format
5.
Using
a tool or writing code to send request and validate the response
Suppose
we want to test a WebService which provides Currency Conversion Facility. It
will the current conversion rates between the different countries currency.
This service we can use in our applications to convert the values from one
currency to the other currency.
Comments
Post a Comment