0% found this document useful (0 votes)
159 views

Web SErvices Complete PDF-merged

The document provides an overview of web services technologies like SOAP, WSDL, and UDDI. It discusses implementing and deploying web service clients and servers using SOAP and REST based approaches with JAX-WS and JAX-RS. The document also covers securing web services and quality of service aspects. Unit 2 focuses on REST architectural styles and building RESTful web services with JAX-RS and JSON.

Uploaded by

Gaurav Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views

Web SErvices Complete PDF-merged

The document provides an overview of web services technologies like SOAP, WSDL, and UDDI. It discusses implementing and deploying web service clients and servers using SOAP and REST based approaches with JAX-WS and JAX-RS. The document also covers securing web services and quality of service aspects. Unit 2 focuses on REST architectural styles and building RESTful web services with JAX-RS and JSON.

Uploaded by

Gaurav Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 276

Web Services

[TCSCSCS506]
~ by Asst. Prof. Shivkumar Chandey,
Department of Computer Science,
Thakur College of Science & Commerce (Autonomous)
Objectives

▪ To understand the details of web services technologies like SOAP, WSDL, and
UDDI. To learn how to implement and deploy web service client and server. To
understand the design principles and application of SOAP and REST based web
services (JAX-Ws and JAX-RS).To understand WCF service. To design secure web
services and QoS of Web Services

10/16/2021 2
Unit II Syllabus

The REST Architectural style :


Introducing HTTP, The core architectural elements of a RESTful system,
Unit II Description and discovery of RESTful web services, Java tools and frameworks
for building RESTful web services, JSON message format and tools and
frameworks around JSON, Build RESTful web services with JAX-RS APIs, The
Description and Discovery of RESTful Web Services, Design guidelines for
building RESTful web services, Secure RESTful web services
Text Books and References

▪ Textbooks:
1. Web Services: Principles and Technology, Michael P. Papazoglou, Pearson
Education Limited, 2008
2. RESTful Java Web Services, Jobinesh Purushothaman, PACKT Publishing,2nd
Edition, 2015
3. Developing Service-Oriented Applications with WCF, Microsoft, 2017
https://docs.microsoft.com/en-us/dotnet/framework/wcf/index
▪ Additional References:
1. Leonard Richardson and Sam Ruby, RESTful Web Services, O’Reilly, 2007
2. The Java EE 6Tutorial, Oracle,
Course Learning Outcomes

▪ Emphasis on SOAP based web services and associated standards such as WSDL.
▪ Design SOAP based / RESTful / WCF services Deal with Security and QoS issues of
Web Services

10/16/2021 5
What is HTTP?

▪ HTTP stands for Hypertext Transfer Protocol.


▪ Hypertext Transfer Protocol is a set of rule which is used for transferring the files
like, audio, video, graphic image, text and other multimedia files on the WWW
(World Wide Web).
▪ HTTP is an application-level protocol. The communication usually takes place
through TCP/IP sockets, but any reliable transport can also be used.
▪ The standard (default) port for HTTP connection is 80, but other port can also be
used.
▪ The first version of HTTP was HTTP/0.9, which was introduced in 1991.
▪ The latest version of HTTP is HTTP/3, which was published in September 2019. It is
an alternative to its processor HTTP/2.

10/16/2021 6
What is HTTP?

▪ This latest version is already in use on the web with the help of UDP (User
Datagram Protocol) instead of TCP (Transmission Control Protocol) for the
underlying transport protocol.
▪ HTTP is used to make communication between a variety of hosts and clients. It
supports a mixture of network configuration.
▪ HTTP is a protocol that is used to transfer the hypertext from the client end to the
server end, but HTTP does not have any security.
▪ Whenever a user opens their Web Browser, that means the user indirectly uses
HTTP.

10/16/2021 7
Three important things about HTTP
Connectionless

▪ HTTP is connectionless. When the HTTP client opens the browser, the browser
initiates an HTTP request. After making the request, the client disconnect from the
server and wait for the response. When the response is ready, the server re-
establish the connection again and delivers the response to the client, after which
the client disconnects the connection. So both client and server know about each
other during the current request and response only.

10/16/2021 9
Media Independent

▪ HTTP is media independent. HTTP can deliver any sort of data, as long as the two
computers can read it.

10/16/2021 10
Stateless

▪ The HTTP is stateless. The client and server just know about each other just during
the current request. If the connection is closed, and two computers want to
connect again, they need to provide information to each other anew, and the
connection is handled as the very first one.

10/16/2021 11
HTTP Needs

▪ The HTTP was designed mainly to fetch the html document and send it to the
client. That all the HTTP was doing in 1991, and it did not support other media
types, it just delivers html document.
▪ It was designed in an exquisite way, and it was continually evolved, and features
were being added to it, it becomes the most convenient way to quickly and reliably
move data on the web.

10/16/2021 12
What is HTTPS?

▪ HTTPS stands for Hypertext Transfer Protocol Secure. HTTPS has a secure transfer.
▪ It was developed by Netscape.
▪ HTTPS is used to encrypt or decrypt user HTTP page or HTTP page requests that
are returned by the webserver.
▪ HTTPS is first used in HTTP/1.1 and is defined in RFC 2616.
▪ In HTTPS, the standard port to transfer the information is 443.

10/16/2021 13
What is HTTPS?

▪ Using the HTTPS, sensitive information that we want to transfer from one user to
another user can be done securely.
▪ HTTPS protocol uses HTTP on connection encrypted by SSL (Secure Socket Layer)
or TLS (Transport Layer Security).
▪ HTTPS protects transmitted data from man-in-the-middle (MITM) attacks and
eavesdropping.
▪ It is the default protocol for conduction financial transactions on the web.

10/16/2021 14
Working of WEB

▪ We will have a client on the left side and server on the right side.
▪ A user wants to see a website, like www.w3cschool/html5.
▪ The user types the URL of a page using a client program, usually a browser.
▪ But first, the computer of the user and the web server need to be physically connected.
That is the job of the internet. Using the TCP/IP protocol, it establishes a connection
using a combination of cable media or wireless media and does all the necessary work
to prepare the environment for the two computers to talk via the HTTP protocol.
▪ When the connection establishes, the client sends a request called the HTTP message,
but because the HTTP is a connectionless protocol, so the client disconnects from the
server and waits for the response.
▪ On the other side, the server processes the request, prepare the response, establish the
connection again, and send it back the response and again in the form of an HTTP
message to the client. Then the two computers completely disconnect.

10/16/2021 15
Working of WEB

10/16/2021 16
Understanding the HTTP request-response model
HTTP Request

▪ HTTP Requests are messages which are sent by the client or user to initiate an action on the
server.

▪ The first line of the message includes the request message from the client to the server, the
method which is applied to the resource, identifier of the resource, and the protocol version.

Syntax:

Request = Request-Line

*(( general-header

| request-header

| entity-header ) CRLF)

CRLF

[ message-body ]

10/16/2021 18
Method and Description

i) GET
This method retrieves information from the given server using a given URI. GET
request can retrieve the data. It cannot apply other effects on the data.
ii) HEAD
The HEAD method is the same as the GET method. It is used to transfer the status
line and header section only.
iii) POST
The POST request sends the data to the server. For example, file upload, customer
information, etc. using the HTML forms.
iv) PUT
The PUT method is used to replace all the current representations of the target
resource with the uploaded content.
10/16/2021 19
Method and Description

v) DELETE
The DELETE method is used to remove all the current representations of the target
resource, which is given by URI.
vi) CONNECT
The CONNECT method is used to establish a tunnel to the server, which is
identified by a given URI.
vii) Return-URI
The Request-URI is a Uniform Resource Identifier. It is used to identify the resource
upon which to apply the request.

10/16/2021 20
Request Header Fields

▪ The request-header fields are used to allow the client to pass additional
information to the server like the request and the client itself. The request header
fields act as request modifiers, with semantics equivalent to the parameters on a
programming language method invocation.

10/16/2021 21
Syntax:
request-header = Accept
| Accept-Charset
| Accept-Encoding
| Accept-Language
| Authorization
| Expect
| From
| Host
| If-Match
| If-Modified-Since
| If-None-Match
| If-Range
| If-Unmodified-Since
| Max-Forwards
| Proxy-Authorization
| Range
| Referer
| TE
| User-Agent
The name of the request-header field can be extended reliably only in combination with a
change in the version of the protocol.
HTTP Response

▪ HTTP Response sent by a server to the client. The response is used to provide the
client with the resource it requested. It is also used to inform the client that the
action requested has been carried out. It can also inform the client that an error
occurred in processing its request.
▪ An HTTP response contains the following things:
– Status Line
– Response Header Fields or a series of HTTP headers
– Message Body
▪ In the request message, each HTTP header is followed by a carriage returns line
feed (CRLF). After the last of the HTTP headers, an additional CRLF is used and
then begins the message body.

10/16/2021 23
Status Line
a) HTTP Version Number

▪ In the response message, the status line is the first line. The status line contains
three items:
▪ It is used to show the HTTP specification to which the server has tried to make the
message comply.
▪ Example
– HTTP-Version = HTTP/1.1

10/16/2021 25
b) Status Code

▪ It is a three-digit number that indicates the result of the request. The first digit
defines the class of the response. The last two digits do not have any
categorization role. There are five values for the first digit, which are as follows:
▪ Code and Description
▪ 1xx: Information
– It shows that the request was received and continuing the process.
▪ 2xx: Success
– It shows that the action was received successfully, understood, and accepted.

10/16/2021 26
b) Status Code

▪ 3xx: Redirection
– It shows that further action must be taken to complete the request.
▪ 4xx: Client Error
– It shows that the request contains incorrect syntax, or it cannot be fulfilled.
▪ 5xx: Server Error
– It shows that the server failed to fulfil a valid request.

10/16/2021 27
c) Reason Phrase

▪ It is also known as the status text. It is a human-readable text that summarizes the
meaning of the status code.
▪ An example of the response line is as follows:
– HTTP/1.1 200 OK
▪ Here,
– HTTP/1.1 is the HTTP version.
– 200 is the status code.
– OK is the reason phrase.

10/16/2021 28
The Resource Identified by a Request

▪ Using the examination of Request-URI and the Host header field, we can
determine the exact resource identified by the Internet request.
▪ An origin server must use the following rules for determining the requested
resource on an HTTP/1.1 request if the origin server does differentiate based on the
host requested.
▪ The host will be part of the Request-URI if Request-URI is an absoluteURI.
▪ The host will be determined by the Host header field value if the Request-URI is not
an absolute URI, and the request includes a header field of the host.
▪ The response MUST be a 400 (Bad Request) error message if the host as
determined by rule 1 or 2 is not a valid host on the server.

10/16/2021 29
Response Header Fields

▪ The HTTP Headers for the response of the server contain the information that a
client can use to find out more about the response, and about the server that sent
it. This information is used to assist the client with displaying the response to a
user, with storing the response for the use of future, and with making further
requests to the server now or in the future.
▪ Note: The name of the Response-header field can be extended reliably only in
combination with a change in the version of the protocol.

10/16/2021 30
Response Header Fields

response-header = Accept-Ranges
| Age
| ETag
| Location
| Proxy-Authenticate
| Retry-After
| Server
| Vary
| WWW-Authenticate

10/16/2021 31
Message Body

▪ The response's message body may be referred to for convenience as a response


body.
▪ The body of the message is used for most responses. The exceptions are where a
server is using certain status codes and where the server is responding to a client
request, which asks for the headers but not the response body.
▪ For a response to a successful request, the body of the message contains either
some information about the status of the action which is requested by the client or
the resource which is requested by the client. For the response to an unsuccessful
request, the body of the message might provide further information about some
action the client needs to take to complete the request successfully or about the
reason for the error.

10/16/2021 32
HTTP Status Code

▪ The Server issues an HTTP Status Code in response to a request of the client made
to the server. Status code is a 3-digit integer.
▪ The first digit of status code is used to specify one of five standard classes of
responses.
▪ The last two digits of status code do not have any categorization role.
▪ The status codes are divided into 5 parts, as follows:

10/16/2021 33
1xx: Information

Message Description
100 Continue It is used to show that the client should continue
with its request. The interim response informs the
client that the request?s initial part has been
received.
101 Switching Protocols It is used to switches the server.
102 Processing This code is used to show that the server has
received and is processing the request. It indicates
that no response is available yet.

103 Early Hints This code is used to return the headers of some
responses before the final HTTP message.

10/16/2021 34
2xx: Successful

Message Description
200 OK This code is used to show that the request is OK.
201 Created This code shows that the request has been fulfilled, which results
in the creation of a new resource.
202 Accepted This code shows that the request is accepted for processing, but
not yet processed completely.
203 Non-authoritative In the entity-header, the information is from a local third party
Information copy. It is not from the original copy.
204 No Content This code is used to show that the request is processed
successfully by the server and not returning any content.
205 Reset Content This code is used to tell the user agent to reset the document
which sent this request.
10/16/2021 35
3xx: Redirection

▪ Refer Table

10/16/2021 36
Message Description
300 Multiple Choices This code is used to indicate that the multiple options for the
resource from which the client may choose.
301 Moved This code shows that the URL of the requested resource has been
Permanently changed permanently. In response, the new URL gives.
302 Found This code is used to show that the requested page has moved
temporarily to a new URL.
303 See Other This code is used to show that the requested page can be found
under another URL using the GET method.
304 No Modified This code is used for caching purposes. It shows the client that the
response has not been modified, so the client can continue to use the
same response?s cached version.
305 Use Proxy This code is used to show that using the proxy; the requested URL
must be accessed, which is mentioned in the Location header.
306 Unused In the previous version, this code is used. This response code is no
longer used, and it is just reserved.
307 Temporary This code is used to show that the requested page has moved
Redirect temporarily to a new URL.
4xx: Client Error

▪ Refer Table

10/16/2021 38
Message Description
400 Bad Request This code is used to indicate that the server did not
understand the request due to invalid syntax.
401 Unauthorized In this code, the requested page needs a username and
password.
402 Payment Required This code reserved for future use.
403 Forbidden This code is used to show that the access is forbidden to
the requested page.
404 No Found This code is used to show that the server cannot find the
requested page.
405 Method Not Allowed It shows that the request method is not supported for the
requested resource.
406 Not Acceptable It is used to show that the server can only generate a
resource that the client does not accept.
407 Proxy Authentication Required It is used to show that the client must first authenticate
itself with the proxy.
408 Request Timeout This code is used to show that the request took longer
than the server was prepared to wait.
5xx: Server Error

Message Description
500 Internal Server Error This code is used to show that the server has encountered a
situation, and it does not know how to handle it.

501 Not Implemented This code shows that the request was not completed, and the
server did not support the functionally required.

502 Bad Gateway This code shows that the request was not completed, and the
server received an invalid response from the upstream server.

503 Service Unavailable This code shows that the request was not completed, and the
server is temporarily overloading or down.

504 Gateway Timeout It shows that the gateway has timed out.
505 HTTP Version Not Supported This code is used to show that the server does not support the
"http protocol" version.
10/16/2021 40
HTTP Message

▪ HTTP Message is used to show how data is exchanged between the client and the
server. It is based on client-server architecture.
▪ An HTTP client is a program that establishes a connection to a server to send one
or more HTTP request messages.
▪ An HTTP server is a program that accepts connections to serve HTTP requests by
sending an HTTP response messages.
▪ The HTTP Messages can be classified as follows:

10/16/2021 41
Message Type

▪ HTTP message consists of an initial request line and an initial response line.
▪ Format:
HTTP-message = Request | Response ; HTTP/1.1 messages

10/16/2021 42
1) Initial Request Line

▪ The initial line is different for the request and for the response. A request-line
consists of three parts: a method name, requested resource's local path, and the
HTTP version being used. All these parts are separated by spaces.
▪ Syntax:
GET /path/to/file/index.html HTTP/1.0
▪ Here,
– GET is the most common HTTP method.
– The path shows the part of the URL after the host name. It is also called a
request URI.
– The version of HTTP always takes the form “HTTP/x.x”, uppercase.

10/16/2021 43
Request HTTP Message

10/16/2021 44
2) Initial Response Line

▪ The initial Response line is also known as the status line. It also has three parts: the
HTTP version, a response status code that gives the result of the request, and the
English reason phrase describing the status code.
▪ Example:
– HTTP/1.0 200 OK
or
– HTTP/1.0 404 Not Found
▪ Here,
– The HTTP version of the response line and request line are the same as
"HTTP/x.x".

10/16/2021 45
Response HTTP Message

10/16/2021 46
Message Headers

▪ The Message header provides information about the request and response. It also
provides information about the object which is sent in the message body. Message
Headers are of four types:
1. General Header: It has general applicability for both request messages and
response messages.
2. Request Header: It has applicability only for the request messages.
3. Response Header: It has applicability only for the response messages.
4. Entity Header: It defines meta-information about the entity-body, and about
the resource identified by request.
▪ All the above headers follow the same generic format. Each of the header fields
consists of a name followed by a colon and the field values as follows:
message-header = field-name ":" [ field-value ]

10/16/2021 47
Message Body

▪ The message body of an HTTP message is used to carry the entire body associated
with the request and response. The message-body differs from the entire-body
only when a transfer-coding has been applied, as indicated by the Transfer-
Encoding header field.
▪ Syntax:
message-body = entity-body | <entity-body encoded as per Transfer-Encoding>
▪ Transfer-Encoding MUST be used to indicate any transfer-codings which is applied
by an application to ensure safe and proper transfer of the message. Transfer-
Encoding is a property of the message.

10/16/2021 48
Message Length

▪ The transfer-length of a message is the length of the message-body, and it appears


in the message.
▪ In a message, when a message body is allowed, and Content-Length is given, its
field value MUST exactly match the number of OCTETs in the message-body. When
an invalid length is received and detected, the HTTP/1.1 user agents MUST notify
the user.

10/16/2021 49
General Header Fields

▪ Some header fields have the applicability for both the request and response
messages. These header fields apply only when the message is transmitted.
▪ Syntax
general-header = Cache-Control

10/16/2021 50
RESTful Web Services

▪ REST stands for REpresentational State Transfer.


▪ It is developed by Roy Thomas Fielding who also developed HTTP.
▪ The main goal of RESTful web services is to make web services more effective.
▪ RESTful web services try to define services using the different concepts that are
already present in HTTP. REST is an architectural approach, not a protocol.
▪ It does not define the standard message exchange format.
▪ We can build REST services with both XML and JSON. JSON is more popular format
with REST.
▪ The key abstraction is a resource in REST. A resource can be anything. It can be
accessed through a Uniform Resource Identifier (URI). For example:

10/16/2021 51
RESTful Web Services

▪ The resource has representations like XML, HTML, and JSON. The current state is
captured by representational resource. When we request a resource, we provide
the representation of the resource.
▪ The important methods of HTTP are:
– GET: It reads a resource.
– PUT: It updates an existing resource.
– POST: It creates a new resource.
– DELETE: It deletes the resource.

10/16/2021 52
RESTful Web Services

▪ For example, if we want to perform the following actions in the social media
application, we get the corresponding results.
– POST /users: It creates a user.
– GET /users/{id}: It retrieve the detail of one user.
– GET /users: It retrieve the detail of all users.
– DELETE /users: It delete all users.
– DELETE /users/{id}: It delete a user.
– GET /users/{id}/posts/post_id: It retrieve the detail of a specific post.
– POST / users/{id}/ posts: It creates a post for a user.
– GET /users/{id}/post: Retrieve all posts for a user

10/16/2021 53
Status Codes of HTTP

▪ HTTP also defines the following standard status code:


– 404: RESOURCE NOT FOUND
– 200: SUCCESS
– 201: CREATED
– 401: UNAUTHORIZED
– 500: SERVER ERROR

10/16/2021 54
RESTful Service Constraints

▪ There must be a service producer and service consumer.


▪ The service is stateless.
▪ The service result must be cacheable.
▪ The interface is uniform and exposing resources.

10/16/2021 55
Advantages of RESTful web services

▪ RESTful web services are platform-independent.


▪ It can be written in any programming language and can be executed on any
platform.
▪ It provides different data format like JSON, text, HTML, and XML.
▪ It is fast in comparison to SOAP because there is no strict specification like SOAP.
▪ These are reusable.
▪ These are language neutral.

10/16/2021 56
The core architectural elements of a
RESTful system

▪ A uniform interface is fundamental to the architecture of any RESTful system.


▪ In plain words, this term refers to a generic interface to manage all interactions
between a client and a server in a unified way. All resources (or business data)
involved in the client-server interactions are dealt with by a fixed set of operations.
▪ The following are core elements that form a uniform interface for a RESTful
system:

10/16/2021 57
Core elements

▪ Resources and their identifiers


▪ Representations of resources
▪ Generic interaction semantics for the REST resources
▪ Self-descriptive messages
▪ Hypermedia as the engine of an application state

10/16/2021 58
Resources

▪ A RESTful resource is anything that is addressable over the Web. By addressable,


we mean resources that can be accessed and transferred between clients and
servers.
▪ Subsequently, a resource is a logical, temporal mapping to a concept in the
problem domain for which we are implementing a solution.
▪ Here are some examples of the REST resources:
– A news story
– The temperature in NY at 4:00 p.m. EST
– A tax return stored in the IRS database
– A student in a classroom in a school
– A search result for a particular item in a Web index, such as Google

10/16/2021 59
URI

▪ A URI is a string of characters used to identify a resource over the Web.


▪ In simple words, the URI in a RESTful web service is a hyperlink to a resource, and it
is the only means for clients and servers to exchange representations.
▪ The client uses a URI to locate the resources over Web and then, sends a request to
the server and reads the response.
▪ In a RESTful system, the URI is not meant to change over time as it may break the
contract between a client and a server.
▪ More importantly, even if the underlying infrastructure or hardware changes (for
example, swapping the database servers) for a server hosting REST APIs, the URIs
for resources are expected to remain the same as long as the web service is up and
running.

10/16/2021 60
The representation of resources

▪ The representation of resources is what is sent back and forth between clients and
servers in a RESTful system.
▪ A representation is a temporal state of the actual data located in some storage
device at the time of a request.
▪ The metadata can contain extra information about the resource, for example,
validation, encryption information, or extra code to be executed at runtime.

10/16/2021 61
The representation of resources

▪ Throughout the life of a web service, there may be a variety of clients requesting
resources.
▪ Different clients can consume different representations of the same resource.
▪ Therefore, a representation can take various forms, such as an image, a text file, an
XML, or a JSON format.
▪ However, all clients will use the same URI with appropriate Accept header values
for accessing the same resource in different representations.

10/16/2021 62
Generic interaction semantics for REST
resources

▪ In a RESTful web service, resources are exchanged between the client and the
server, which represent the business entities or data.
▪ HTTP specifies methods or actions for the resources. The most commonly used
HTTP methods or actions are POST, GET, PUT, and DELETE.
▪ This clearly simplifies the REST API design and makes it more readable.

10/16/2021 63
Generic interaction semantics for REST
resources

▪ In a RESTful system, we can easily map our CRUD actions on the resources to the
appropriate HTTP methods such as POST, GET, PUT, and DELETE. This is shown in
the following table:

10/16/2021 64
The HTTP GET method

▪ The method, GET, is used to retrieve resources.


▪ Before digging into the actual mechanics of the HTTP GET request, we first need to
determine what a resource is in the context of our web service and what type of
representation we are exchanging.
▪ For the rest of this section, we will use the example of a RESTful web service
handling department details for an organization.
▪ For this service, the JSON representation of a department looks like the following:
{"departmentId":10,"departmentName":"IT","manager":"John Chen"}

10/16/2021 65
Hypermedia as the Engine of Application
State

▪ Hypermedia as the Engine of Application State (HATEOAS) is an important


principle of the REST application architecture.
▪ The principle is that the model of application changes from one state to another by
traversing the hyperlinks present in the current set of resource representations (the
model).
▪ Let's learn this principle in detail.

10/16/2021 66
HATEOAS

▪ In a RESTful system, there is no fixed interface between the client and the server as
you may see in a conventional client-server communication model such as
Common Object Request Broker Architecture (CORBA) and Java Remote Method
Invocation (Java RMI).
▪ With REST, the client just needs to know how to deal with the hypermedia links
present in the response body; next, the call to retrieve the appropriate resource
representation is made by using these dynamic media links.
▪ This concept makes the client-server interaction very dynamic and keeps it
different from the other network application architectures.

10/16/2021 67
Description and discovery of RESTful
web services

▪ As you may know, WSDL is used for describing the functionality offered by a SOAP
web service.
▪ For a SOAP web service, this is a widely accepted standard and is supported by
many enterprises today. In contrast, for RESTful web services, there is no such
standard and you may find different metadata formats used by various enterprises.
▪ However, in general, you may see the following goals in common among all these
metadata formats for RESTful APIs, although they differ in their syntax and
semantics:

10/16/2021 68
Description and discovery of RESTful
web services

▪ Entry points for the service


▪ Resource paths for accessing each resource
▪ HTTP methods allowed to access these resources, such as GET, POST, PUT, and
DELETE
▪ Additional parameters that need to be supplied with these methods, such as pagination
parameters, while reading large collections
▪ Format types used for representing the request and response body contents such as
JSON, XML, and TEXT
▪ Status codes and error messages returned by the APIs
▪ Human readable documentation for REST APIs, which includes the documentation of
the request methods, input and output parameters, response codes (success or error),
API security, and business logic

10/16/2021 69
Note

▪ Some of the popular metadata formats used for describing REST APIs are Web
Application Description Language (WADL), Swagger, RESTful API Modeling
Language (RAML), API Blueprint, and WSDL 2.0.

10/16/2021 70
Web Application Description Language

▪ Web Application Description Language (WADL) is an XML description of HTTP


based web applications such as RESTful web services.
▪ WADL was submitted to the World Wide Web Consortium (W3C) by Sun in 2009 but
has not been standardized yet.
▪ WADL models the resources provided by a RESTful web service with relationships
between the resources. It also allows you to clearly represent the media types used
for the request and response contents.

10/16/2021 71
Swagger

▪ Swagger offers a specification and complete framework implementation for


describing, producing, consuming, and visualizing RESTful web services.
▪ The Swagger framework works with many of the popular programming languages,
such as Java, Scala, Clojure, Groovy, JavaScript, and .Net.
▪ Swagger was initially developed by Wordnik (a property of Reverb) for meeting
their in-house requirements, and the first version was released in 2011.
▪ The current release is Swagger 2.0, and it is 100 percent open source, supported by
many vendors, such as PayPal, Apigee, and 3scale.

10/16/2021 72
Swagger framework

▪ The Swagger framework has the following three major components:


▪ Server:
– This component hosts the RESTful web API descriptions for the services that
clients want to use
▪ Client:
– This component uses the RESTful web API descriptions from the server to
provide an automated interfacing mechanism to invoke the REST APIs
▪ User interface:
– This part of the framework reads a description of the APIs from the server and
renders it as a web page and provides an interactive sandbox to test the APIs

10/16/2021 73
Java tools and frameworks for building
RESTful web services
Java API for RESTful web services
(JAX-RS)

▪ The Java API for RESTful web services (JAX-RS) is the Java API for creating RESTful
web services following the REST architectural pattern.
▪ JAX-RS is a part of the Java Platform Enterprise Edition (Java EE) platform and is
designed to be a standard and portable solution.
▪ There are many reference implementations available for JAX-RS today. Some of
the most popular implementations are Jersey, Apache CXF, RESTEasy, and Restlet.
▪ At this juncture, it is worth mentioning that most of the frameworks in the
preceding list, such as Jersey and Apache CXF, are not just limited to reference
implementations of the JAX-RS specifications, but they also offer many additional
features on top of the specifications.

10/16/2021 75
RESTX

▪ One such framework is RESTX, which is an open source Java REST framework and
is primarily focused on the server-side REST API development. This is relatively
new in the market and simplifies the REST API development.

10/16/2021 76
Spark

▪ Spark is another framework that falls into this category. It is a Java web framework
with support for building REST APIs. Spark 2.0 is built using Java 8, leveraging all
the latest improvements of the Java language.

10/16/2021 77
Play

▪ Play is another framework worth mentioning in this category. It is a Java (and


Scala)-based web application framework with inherent support for building
RESTful web services.

10/16/2021 78
JSON message format and tools and
frameworks around JSON
JSON

▪ JSON or JavaScript Object Notation is a lightweight text-based open standard


designed for human-readable data interchange.
▪ Conventions used by JSON are known to programmers, which include C, C++, Java,
Python, Perl, etc.

10/16/2021 80
JSON

▪ The format was specified by Douglas Crockford.


▪ It was designed for human-readable data interchange.
▪ It has been extended from the JavaScript scripting language.
▪ The filename extension is .json.
▪ JSON Internet Media type is application/json.
▪ The Uniform Type Identifier is public.json.

10/16/2021 81
Uses of JSON

▪ It is used while writing JavaScript based applications that includes browser


extensions and websites.
▪ JSON format is used for serializing and transmitting structured data over network
connection.
▪ It is primarily used to transmit data between a server and web applications.
▪ Web services and APIs use JSON format to provide public data.
▪ It can be used with modern programming languages.

10/16/2021 82
Characteristics of JSON

▪ JSON is easy to read and write.


▪ It is a lightweight text-based interchange format.
▪ JSON is language independent.

10/16/2021 83
JSON Example

▪ JSON example can be created by object and array. Each object can have different
data such as text, number, boolean etc. Let's see different JSON examples using
object and array.

10/16/2021 84
JSON Object Example

▪ A JSON object contains data in the form of key/value pair. The keys are strings and
the values are the JSON types. Keys and values are separated by colon. Each entry
(key/value pair) is separated by comma.
▪ The { (curly brace) represents the JSON object.

10/16/2021 85
//JSON Example
{
"employee":
{
"name": “John",
"salary": 50000,
"married": true
}
}
JSON Array example

▪ The [ (square bracket) represents the JSON array. A JSON array can have values
and objects.
▪ Let's see the example of JSON array having values.
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
▪ Let's see the example of JSON array having objects.
[
{"name":“john", "email":“[email protected]"},
{"name":“paul", "email":“[email protected]"}
]

10/16/2021 87
JSON v/s XML

▪ The following are the differences between the json and xml:
▪ JSON vs XML.docx

10/16/2021 88
Basic data types available with JSON
Number

▪ This type is used for storing a signed decimal number that may optionally contain a
fractional part. Both integer and floating point numbers are represented by using
this data type.
▪ The following example uses the decimal data type for storing totalWeight:
{"totalWeight": 123.456}

10/16/2021 90
String

▪ This type represents a sequence of zero or more characters. Strings are surrounded
with double quotation marks and support a backslash escaping syntax.
▪ Here is an example of the string data type:
{"firstName": “Shiv"}

10/16/2021 91
Boolean

▪ This type represents either a true or a false value. The Boolean type is used for
representing whether a condition is true or false, or to represent two states of a
variable (true or false) in the code.
▪ Here is an example representing a Boolean value:
{"isValidEntry": true}

10/16/2021 92
Array

▪ This type represents an ordered list of zero or more values, each of which can be of
any type. In this representation, comma-separated values are enclosed in square
brackets.
▪ The following example represents an array of fruits:
{"fruits": ["apple", "banana", "orange"]}

10/16/2021 93
Object

▪ This type is an unordered collection of comma-separated attribute value pairs


enclosed in curly braces.
▪ All attributes must be strings and should be distinct from each other within that
object.
▪ The following example illustrates an object representation in JSON:
{"departmentId":10,
"departmentName":"IT",
"manager":"John Chen"}

10/16/2021 94
null

▪ This type indicates an empty value, represented by using the word null.
▪ The following example uses null as the value for the error attribute of an object:
{"error":null}

10/16/2021 95
JSON message format and tools and
frameworks around JSON
APIs and Framework

▪ There are many Java-based frameworks available today for processing JSON.
▪ Following are the APIs available on the Java EE platform for processing JSON.
▪ Java EE 7 has standardized the JSON processing APIs with Java Specification
Request (JSR), that is, JSR 353 - Java API for JSON Processing.
▪ This JSR offers portable APIs to parse, generate, transform, and query JSON data.
▪ The JSR 353 APIs can be classified into two categories on the basis of the
processing model followed by the APIs:
– Object model API
– Streaming model API

10/16/2021 97
Jackson

▪ Jackson is a simple java based library to serialize java objects to JSON and vice
versa.

10/16/2021 98
Features

▪ Easy to use. - jackson API provides a high level facade to simplify commonly used
use cases.
▪ No need to create mapping. - jackson API provides default mapping for most of the
objects to be serialized.
▪ Performance. - jackson is quiet fast and is of low memory footprint and is suitable
for large object graphs or systems.
▪ Clean JSON. - jackson creates a clean and compact JSON results which is easy to
read.
▪ No Dependency. - jackson library does not require any other library apart from jdk.
▪ Open Source - jackson library is open source and is free to use.

10/16/2021 99
GSON

▪ Google Gson is a simple Java-based library to serialize Java objects to JSON and
vice versa. It is an open-source library developed by Google.

10/16/2021 100
Features of Gson

▪ Here is a list of some of the most prominent features of Gson −


▪ Easy to use − Gson API provides a high-level facade to simplify commonly used use-
cases.
▪ No need to create mapping − Gson API provides default mapping for most of the
objects to be serialized.
▪ Performance − Gson is quite fast and is of low memory footprint. It is suitable for
large object graphs or systems.
▪ Clean JSON − Gson creates a clean and compact JSON result which is easy to read.
▪ No Dependency − Gson library does not require any other library apart from JDK.
▪ Open Source − Gson library is open source; it is freely available.

10/16/2021 101
Three Ways of Processing JSON

▪ Gson provides three alternative ways to process JSON −

10/16/2021 102
Streaming API

▪ It reads and writes JSON content as discrete events. JsonReader and JsonWriter
read/write the data as token, referred as JsonToken.
▪ It is the most powerful approach among the three approaches to process JSON. It
has the lowest overhead and it is quite fast in read/write operations. It is analogous
to Stax parser for XML.

10/16/2021 103
Tree Model

▪ It prepares an in-memory tree representation of the JSON document. It builds a


tree of JsonObject nodes. It is a flexible approach and is analogous to DOM parser
for XML.

10/16/2021 104
Data Binding

▪ It converts JSON to and from POJO (Plain Old Java Object) using property accessor.
Gson reads/writes JSON using data type adapters. It is analogous to JAXB parser
for XML.

10/16/2021 105
Secure RESTful web services

▪ As RESTful Web Services work with HTTP URL Paths, it is very important to
safeguard a RESTful Web Service in the same manner as a website is secured.
▪ Following are the best practices to be adhered to while designing a RESTful Web
Service −

10/16/2021 106
Validation

▪ Validate all inputs on the server. Protect your server against SQL or NoSQL
injection attacks.

10/16/2021 107
Session Based Authentication

▪ Use session based authentication to authenticate a user whenever a request is


made to a Web Service method.

10/16/2021 108
No Sensitive Data in the URL

▪ Never use username, password or session token in a URL, these values should be
passed to Web Service via the POST method.

10/16/2021 109
Restriction on Method Execution

▪ Allow restricted use of methods like GET, POST and DELETE methods. The GET
method should not be able to delete data.

10/16/2021 110
Validate Malformed XML/JSON

▪ Check for well-formed input passed to a web service method.

10/16/2021 111
Throw generic Error Messages

▪ A web service method should use HTTP error messages like 403 to show access
forbidden, etc.

10/16/2021 112
Google Classroom code for
“Web Services”

▪ Join the Google Classroom by Using following Code:

57ue75w

10/16/2021 113
Thank You!!!Any Query?
[email protected]
Shivkumar Chandey
(+91 9987389441)
Scan QR Code to connect
on LinkedIn

10/16/2021 114
Web Services
[TCSCSCS506]
~ by Asst. Prof. Shivkumar Chandey,
Department of Computer Science,
Thakur College of Science & Commerce (Autonomous)
Objectives

▪ To understand the details of web services technologies like SOAP, WSDL, and
UDDI. To learn how to implement and deploy web service client and server. To
understand the design principles and application of SOAP and REST based web
services (JAX-Ws and JAX-RS).To understand WCF service. To design secure web
services and QoS of Web Services

10/10/2021 2
Unit III Syllabus

Developing Service-Oriented Applications with WCF :


What Is Windows Communication Foundation, Fundamental Windows
Unit III Communication Foundation Concepts, Windows Communication Foundation
Architecture, WCF and .NET Framework Client Profile, Basic WCF
Programming, WCF Feature Details. Web Service QoS
Text Books and References

▪ Textbooks:
1. Web Services: Principles and Technology, Michael P. Papazoglou, Pearson
Education Limited, 2008
2. RESTful Java Web Services, Jobinesh Purushothaman, PACKT Publishing,2nd
Edition, 2015
3. Developing Service-Oriented Applications with WCF, Microsoft, 2017
https://docs.microsoft.com/en-us/dotnet/framework/wcf/index
▪ Additional References:
1. Leonard Richardson and Sam Ruby, RESTful Web Services, O’Reilly, 2007
2. The Java EE 6Tutorial, Oracle,
Course Learning Outcomes

▪ Emphasis on SOAP based web services and associated standards such as WSDL.
▪ Design SOAP based / RESTful / WCF services Deal with Security and QoS issues of
Web Services

10/10/2021 5
What is Windows Communication
Foundation?

▪ Windows Communication Foundation (WCF) is a framework for building service-


oriented applications.
▪ Using WCF, you can send data as asynchronous messages from one service
endpoint to another.
▪ A service endpoint can be part of a continuously available service hosted by IIS, or
it can be a service hosted in an application.
▪ An endpoint can be a client of a service that requests data from a service endpoint.
▪ The messages can be as simple as a single character or word sent as XML, or as
complex as a stream of binary data.

10/10/2021 6
A few sample scenarios include:

▪ A secure service to process business transactions.


▪ A service that supplies current data to others, such as a traffic report or other
monitoring service.
▪ A chat service that allows two people to communicate or exchange data in real
time.
▪ A dashboard application that polls one or more services for data and presents it in a
logical presentation.

10/10/2021 7
More on WCF

▪ The elementary feature of WCF is interoperability.


▪ It is one of the latest technologies of Microsoft that is used to build service-
oriented applications.
▪ Based on the concept of message-based communication, in which an HTTP
request is represented uniformly, WCF makes it possible to have a unified API
irrespective of diverse transport mechanisms.
▪ WCF was released for the first time in 2006 as a part of the .NET framework with
Windows Vista, and then got updated several times.
▪ WCF 4.5 is the most recent version that is now widely used.

10/10/2021 8
Features of WCF
Service Orientation

▪ One consequence of using WS standards is that WCF enables you to create service
oriented applications.
▪ Service-oriented architecture (SOA) is the reliance on Web services to send and
receive data.
▪ The services have the general advantage of being loosely-coupled instead of hard-
coded from one application to another.
▪ A loosely-coupled relationship implies that any client created on any platform can
connect to any service as long as the essential contracts are met.

10/10/2021 10
Interoperability

▪ WCF implements modern industry standards for Web service interoperability.

10/10/2021 11
Multiple Message Patterns

▪ Messages are exchanged in one of several patterns. The most common pattern is
the request/reply pattern, where one endpoint requests data from a second
endpoint. The second endpoint replies.
▪ There are other patterns such as a one-way message in which a single endpoint
sends a message without any expectation of a reply.
▪ A more complex pattern is the duplex exchange pattern where two endpoints
establish a connection and send data back and forth, similar to an instant
messaging program

10/10/2021 12
Service Metadata

▪ WCF supports publishing service metadata using formats specified in industry


standards such as WSDL, XML Schema and WS-Policy.
▪ This metadata can be used to automatically generate and configure clients for
accessing WCF services.
▪ Metadata can be published over HTTP and HTTPS or using the Web Service
Metadata Exchange standard.

10/10/2021 13
Data Contracts

▪ Because WCF is built using the .NET Framework, it also includes code-friendly
methods of supplying the contracts you want to enforce.
▪ One of the universal types of contracts is the data contract. In essence, as you code
your service using Visual C# or Visual Basic, the easiest way to handle data is by
creating classes that represent a data entity with properties that belong to the data
entity.
▪ WCF includes a comprehensive system for working with data in this easy manner.
Once you have created the classes that represent data, your service automatically
generates the metadata that allows clients to comply with the data types you have
designed.

10/10/2021 14
Security

▪ Messages can be encrypted to protect privacy and you can require users to
authenticate themselves before being allowed to receive messages.
▪ Security can be implemented using well-known standards such as SSL or WS-
SecureConversation.

10/10/2021 15
Multiple Transports and Encodings

▪ Messages can be sent on any of several built-in transport protocols and encodings.
▪ The most common protocol and encoding is to send text encoded SOAP messages
using the HyperText Transfer Protocol (HTTP) for use on the World Wide Web.
▪ Alternatively, WCF allows you to send messages over TCP, named pipes, or MSMQ.
▪ These messages can be encoded as text or using an optimized binary format.
Binary data can be sent efficiently using the MTOM standard.
▪ If none of the provided transports or encodings suit your needs you can create your
own custom transport or encoding.

10/10/2021 16
Reliable and Queued Messages

▪ WCF supports reliable message exchange using reliable sessions implemented over
WS-Reliable Messaging and using MSMQ.

10/10/2021 17
Durable Messages

▪ A durable message is one that is never lost due to a disruption in the


communication.
▪ The messages in a durable message pattern are always saved to a database.
▪ If a disruption occurs, the database allows you to resume the message exchange
when the connection is restored.
▪ You can also create a durable message using the Windows Workflow Foundation
(WF).

10/10/2021 18
Transactions

▪ WCF also supports transactions using one of three transaction models: WS-
AtomicTransactions, the APIs in the System. Transactions namespace, and
Microsoft Distributed Transaction Coordinator.

10/10/2021 19
AJAX and REST Support

▪ REST is an example of an evolving Web 2.0 technology.


▪ WCF can be configured to process "plain" XML data that is not wrapped in a SOAP
envelope.
▪ WCF can also be extended to support specific XML formats, such as ATOM (a
popular RSS standard), and even non-XML formats, such as JavaScript Object
Notation (JSON).

10/10/2021 20
Extensibility

▪ The WCF architecture has a number of extensibility points. If extra capability is


required, there are a number of entry points that allow you to customize the
behavior of a service.

10/10/2021 21
Fundamental Concepts of WCF
Message

▪ This is a communication unit that comprises of several parts apart from the body.
Message instances are sent as well as received for all types of communication
between the client and the service.

10/10/2021 23
Endpoint

▪ It defines the address where a message is to be sent or received. It also specifies


the communication mechanism to describe how the messages will be sent along
with defining the set of messages.
▪ A structure of an endpoint comprises of the following parts −

10/10/2021 24
Address

▪ Address specifies the exact location to receive the messages and is specified as a
Uniform Resource Identifier (URI). It is expressed as scheme://domain[:port]/[path].
Take a look at the address mentioned below −
net.tcp://localhost:9000/ServiceA
▪ Here, 'net.tcp' is the scheme for the TCP protocol. The domain is 'localhost' which
can be the name of a machine or a web domain, and the path is 'ServiceA'.

10/10/2021 25
Binding

▪ It defines the way an endpoint communicates. It comprises of some binding


elements that make the infrastructure for communication. For example, a binding
states the protocols used for transport like TCP, HTTP, etc., the format of message
encoding, and the protocols related to security as well as reliability.

10/10/2021 26
Contracts

▪ It is a collection of operations that specifies what functionality the endpoint


exposes to the client. It generally consists of an interface name.

10/10/2021 27
Hosting

▪ Hosting from the viewpoint of WCF refers to the WCF service hosting which can be
done through many available options like self-hosting, IIS hosting, and WAS
hosting.

10/10/2021 28
Metadata

▪ This is a significant concept of WCF, as it facilitates easy interaction between a


client application and a WCF service. Normally, metadata for a WCF service is
generated automatically when enabled, and this is done by inspection of service
and its endpoints.

10/10/2021 29
WCF Client

▪ A client application that gets created for exposing the service operations in the
form of methods is known as a WCF client. This can be hosted by any application,
even the one that does service hosting.

10/10/2021 30
Channel

▪ Channel is a medium through which a client communicates with a service. Different


types of channels get stacked and are known as Channel Stacks.

10/10/2021 31
SOAP

▪ Although termed as ‘Simple Object Access Protocol’, SOAP is not a transport


protocol; instead it is an XML document comprising of a header and body section.

10/10/2021 32
Advantages of WCF

▪ It is interoperable with respect to other services. This is in sharp contrast to .NET


Remoting in which both the client and the service must have .Net.
▪ WCF services offer enhanced reliability as well as security in comparison to ASMX
(Active Server Methods) web services.
▪ Implementing the security model and binding change in WCF do not require a
major change in coding. Just a few configuration changes is required to meet the
constraints.

10/10/2021 33
Advantages of WCF

▪ WCF has built-in logging mechanism whereas in other technologies, it is essential


to do the requisite coding.
▪ WCF has integrated AJAX and support for JSON (JavaScript object notation).
▪ It offers scalability and support for up-coming web service standards.
▪ It has a default security mechanism which is extremely robust.

10/10/2021 34
Windows Communication Foundation
Architecture
WCF Architecture

▪ WCF has a layered architecture that offers ample support for developing various
distributed applications.
▪ The architecture is explained below in detail.

10/10/2021 36
Contracts

▪ The contracts layer is just next to the application layer and contains information
similar to that of a real-world contract that specifies the operation of a service and
the kind of accessible information it will make.
▪ Contracts are basically of four types discussed below in brief.

10/10/2021 38
Types of contract

▪ Service contract:
– This contract provides information to the client as well as to the outer world
about the offerings of the endpoint, and the protocols to be used in the
communication process.
▪ Data contract:
– The data exchanged by a service is defined by a data contract. Both the client
and the service has to be in agreement with the data contract.

10/10/2021 39
Types of contract

▪ Message contract:
– A data contract is controlled by a message contract. It primarily does the
customization of the type formatting of the SOAP message parameters.
– Here, it should be mentioned that WCF employs SOAP format for the purpose of
communication.
▪ Policy and Binding:
– There are certain pre-conditions for communication with a service, and such
conditions are defined by policy and binding contract.
– A client needs to follow this contract.

10/10/2021 40
Service Runtime

▪ The service runtime layer is just below the contracts layer. It specifies the various
service behaviors that occur during runtime.
▪ There are many types of behaviors that can undergo configuration and come under
the service runtime.

10/10/2021 41
Service Runtime

▪ Throttling Behavior − Manages the number of messages processed.


▪ Error Behavior − Defines the result of any internal service error occurrence.
▪ Metadata Behavior − Specifies the availability of metadata to the outside world.
▪ Instance Behavior − Defines the number of instances that needs to be created to
make them available for the client.

10/10/2021 42
Service Runtime

▪ Transaction Behavior − Enables a change in transaction state in case of any failure.


▪ Dispatch Behavior − Controls the way by which a message gets processed by the
infrastructure of WCF.
▪ Concurrency Behavior − Controls the functions that run parallel during a client-
server communication.
▪ Parameter Filtering − Features the process of validation of parameters to a method
before it gets invoked.

10/10/2021 43
Messaging

▪ This layer, composed of several channels, mainly deals with the message content
to be communicated between two endpoints.
▪ A set of channels form a channel stack and the two major types of channels that
comprise the channel stack are the following ones −

10/10/2021 44
Transport Channels

▪ These channels are present at the bottom of a stack and are accountable for
sending and receiving messages using transport protocols like HTTP, TCP, Peer-to-
Peer, Named Pipes, and Microsoft Message Queuing (MSMQ).

10/10/2021 45
Protocol Channels

▪ Present at the top of a stack, these channels also known as layered channels,
implement wire-level protocols by modifying messages.

10/10/2021 46
Activation and Hosting

▪ The last layer of WCF architecture is the place where services are actually hosted or
can be executed for easy access by the client.
▪ This is done by various mechanisms discussed below in brief.

10/10/2021 47
Activation and Hosting

▪ IIS − IIS stands for Internet Information Service. It offers a myriad of advantages
using the HTTP protocol by a service. Here, it is not required to have the host code
for activating the service code; instead, the service code gets activated
automatically.
▪ Windows Activation Service − This is popularly known as WAS and comes with IIS
7.0. Both HTTP and non-HTTP based communication is possible here by using TCP
or Namedpipe protocols.

10/10/2021 48
Activation and Hosting

▪ Self-hosting − This is a mechanism by which a WCF service gets self-hosted as a


console application. This mechanism offers amazing flexibility in terms of choosing
the desired protocols and setting own addressing scheme.
▪ Windows Service − Hosting a WCF service with this mechanism is advantageous, as
the services then remain activated and accessible to the client due to no runtime
activation.

10/10/2021 49
Difference between WCF and Web service

▪ Web service is a part of WCF. WCF offers much more flexibility and portability to
develop a service when comparing to web service.
▪ Still we are having more advantages over Web service, following table provides
detailed difference between them.

10/10/2021 50
Features Web Service WCF
It can be hosted in IIS, windows activation
Hosting It can be hosted in IIS
service, Self-hosting, Windows service
[WebService] attribute has to be added to [ServiceContraact] attribute has to be added
Programming
the class to the class
[WebMethod] attribute represents the [OperationContract] attribute represents
Model
method exposed to client the method exposed to client
One-way, Request- Response are the One-Way, Request-Response, Duplex are
Operation different operations supported in web different type of operations supported in
service WCF
System.Xml.serialization name space is System.Runtime.Serialization namespace is
XML
used for serialization used for serialization
XML 1.0, MTOM(Message Transmission
Encoding XML 1.0, MTOM, Binary, Custom
Optimization Mechanism), DIME, Custom
Can be accessed through HTTP, TCP, Can be accessed through HTTP, TCP, Named
Transports
Custom pipes, MSMQ,P2P, Custom
Protocols Security Security, Reliable messaging, Transactions
WCF features supported by the .NET
Framework Client Profile

▪ The following Windows Communication Foundation features are supported by


.NET Framework Client Profile:
▪ All of WCF is supported except for Cardspace and web hosting.
▪ Remoting TCP/IP channels are supported.
▪ Asmx (Web Services) are not supported.

10/10/2021 52
Basic Programming Lifecycle

▪ Define the service contract. A service contract specifies the signature of a service,
the data it exchanges, and other contractually required data.
▪ Implement the contract. To implement a service contract, create a class that
implements the contract and specify custom behaviors that the runtime should
have.
▪ Configure the service by specifying endpoints and other behavior information.
▪ Host the service.
▪ Build a client application.

10/10/2021 53
Web Service QoS

▪ Quality of Service is the idea that transmission rates, error rates, and other
characteristics can be measured, improved, and, to some extent, guaranteed in
advance.
▪ Quality of Service for Web Service can be refers to a web service’s ability to achieve
it’s purpose and deal with other service network performance elements

10/10/2021 54
A broad definition

▪ QoS is a set of methods for differentiating traffic and services.


– introducing an element of predictability and consistency into a highly variable
best-effort network
– obtaining higher network throughput while maintaining consistent behavior
– matching network resources to application demands

10/10/2021 55
Google Classroom code for
“Web Services”

▪ Join the Google Classroom by Using following Code:

57ue75w

10/10/2021 56
Thank You!!!Any Query?
[email protected]
Shivkumar Chandey
(+91 9987389441)
Scan QR Code to connect
on LinkedIn

10/10/2021 57
Web Services
[TCSCSCS506]
~ by Asst. Prof. Shivkumar Chandey,
Department of Computer Science,
Thakur College of Science & Commerce (Autonomous)
Objectives

▪ To understand the details of web services technologies like SOAP, WSDL, and
UDDI. To learn how to implement and deploy web service client and server. To
understand the design principles and application of SOAP and REST based web
services (JAX-Ws and JAX-RS).To understand WCF service. To design secure web
services and QoS of Web Services

8/2/2021 2
Unit I Syllabus

Web services basics:


What Are Web Services? Types of Web Services Distributed computing
Unit I infrastructure, overview of XML, SOAP, Building Web Services with JAX-WS,
Registering and Discovering Web Services, Service Oriented Architecture, Web
Services Development Life Cycle, Developing and consuming simple Web
Services across platform
Text Books and References

▪ Textbooks:
1. Web Services: Principles and Technology, Michael P. Papazoglou, Pearson
Education Limited, 2008
2. RESTful Java Web Services, Jobinesh Purushothaman, PACKT Publishing,2nd
Edition, 2015
3. Developing Service-Oriented Applications with WCF, Microsoft, 2017
https://docs.microsoft.com/en-us/dotnet/framework/wcf/index
▪ Additional References:
1. Leonard Richardson and Sam Ruby, RESTful Web Services, O’Reilly, 2007
2. The Java EE 6Tutorial, Oracle,
Course Learning Outcomes

▪ Emphasis on SOAP based web services and associated standards such as WSDL.
▪ Design SOAP based / RESTful / WCF services Deal with Security and QoS issues of
Web Services

8/2/2021 5
What is Service?

▪ A service is a well-defined, self-contained function that represents a unit of


functionality.
▪ A service can exchange information from another service. It is not dependent on
the state of another service.
▪ It uses a loosely coupled, message-based communication model to communicate
with applications and other services.

8/2/2021 6
Introduction to Web Services

▪ A Web Service is can be defined by following ways:


– It is a client-server application or application component for communication.
– The method of communication between two devices over the network.
– It is a software system for the interoperable machine to machine
communication.
– It is a collection of standards or protocols for exchanging information between
two devices or application.

8/2/2021 7
Why do you need a Web Service?

▪ Modern day business applications use variety of programming platforms to


develop web-based applications. Some applications may be developed in Java,
others in .Net, while some other in Angular JS, Node.js, etc.
▪ Most often than not, these heterogeneous applications need some sort of
communication to happen between them. Since they are built using different
development languages, it becomes really difficult to ensure accurate
communication between applications.
▪ Here is where web services come in. Web services provide a common platform that
allows multiple applications built on various programming languages to have the
ability to communicate with each other.

8/2/2021 8
Let's understand it by the given figure

▪ As you can see in the figure, Java, .net, and PHP applications can communicate with
other applications through web service over the network. For example, the Java
application can interact with Java, .Net, and PHP applications. So web service is a
language independent way of communication.

8/2/2021 9
Simple Definition of Web Service

▪ A Web service is a self-describing, self-contained software module available via a


network, such as the Internet, which completes tasks, solves problems, or conducts
transactions on behalf of a user or application.

8/2/2021 10
Moreover, A Web service can be

▪ A Web service can be:


i. a self-contained business task, such as a funds withdrawal or funds deposit
service;
ii. a full-fledged business process, such as the automated purchasing of office
supplies;
iii. an application, such as a life insurance application or demand forecasts and
stock replenishment; or
iv. a service-enabled resource, such as access to a particular back-end database
containing patient medical records.

8/2/2021 11
Web Services Advantages

▪ We already understand why web services came about in the first place, which was
to provide a platform which could allow different applications to talk to each other.
▪ But let's look at the list of web services advantages for why it is important to use
web services.
1. Exposing Business Functionality on the network
2. Interoperability amongst applications
3. A Standardized Protocol which everybody understands
4. Reduction in cost of communication

8/2/2021 12
Web Service Characteristics

▪ Web services have the following special behavioral characteristics:


▪ They are XML-Based - Web Services uses XML to represent the data at the
representation and data transportation layers. Using XML eliminates any
networking, operating system, or platform sort of dependency since XML is the
common language understood by all.
▪ Loosely Coupled – Loosely coupled means that the client and the web service are
not bound to each other, which means that even if the web service changes over
time, it should not change the way the client calls the web service. Adopting a
loosely coupled architecture tends to make software systems more manageable
and allows simpler integration between different systems.

8/2/2021 13
Web Service Characteristics

▪ Synchronous or Asynchronous functionality- Synchronicity refers to the binding of


the client to the execution of the service. In synchronous operations, the client will
actually wait for the web service to complete an operation. An example of this is
probably a scenario wherein a database read and write operation are being
performed
▪ Ability to support Remote Procedure Calls (RPCs) - Web services enable clients to
invoke procedures, functions, and methods on remote objects using an XML-based
protocol. Remote procedures expose input and output parameters that a web
service must support.

8/2/2021 14
Web Service Characteristics

▪ Supports Document Exchange - One of the key benefits of XML is its generic way of
representing not only data but also complex documents.
▪ These documents can be as simple as representing a current address, or they can
be as complex as representing an entire book.

8/2/2021 15
Web Service Components

▪ Over the past few years, four primary technologies have emerged as worldwide
standards that make up the core of today's web services technology. These
technologies are discussed below.
– XML-RPC
– SOAP
– WSDL
– UDDI

8/2/2021 16
XML-RPC

▪ This is the simplest XML-based protocol for exchanging information between


computers.
▪ XML-RPC is a simple protocol that uses XML messages to perform RPCs.
▪ Requests are encoded in XML and sent via HTTP POST.
▪ XML responses are embedded in the body of the HTTP response.
▪ XML-RPC is platform-independent.
▪ XML-RPC allows diverse applications to communicate.
▪ A Java client can speak XML-RPC to a Perl server.
▪ XML-RPC is the easiest way to get started with web services.

8/2/2021 17
SOAP-Simple Object Access Protocol

▪ SOAP is an XML-based protocol for exchanging information between computers.


▪ SOAP is a communication protocol.
▪ SOAP is for communication between applications.
▪ SOAP is a format for sending messages.
▪ SOAP is designed to communicate via Internet.
▪ SOAP is platform independent.
▪ SOAP is language independent.
▪ SOAP is simple and extensible.

8/2/2021 18
WSDL-Web Services Description Language

▪ WSDL is an XML-based language for describing web services and how to access
them.
▪ WSDL was developed jointly by Microsoft and IBM.
▪ WSDL is an XML based protocol for information exchange in decentralized and
distributed environments.
▪ WSDL is the standard format for describing a web service.
▪ WSDL definition describes how to access a web service and what operations it will
perform.
▪ WSDL is a language for describing how to interface with XML-based services.

8/2/2021 19
Elements of WSDL

WSDL 1.1 WSDL 2.0 Description


Term Term
Service Service It is a set of system functions.
Port Endpoint It is an endpoint that defines a combination of binding and network addresses.

Binding Binding It specifies the interface and defines the SOAP binding style. It also defines the
operations.
PortType Interface An abstract set of services supported by one or more endpoints.
Operation Operation Abstract detail of an action supported by the service. It defines the SOAP
actions and the way of encoding the message.
Message N/A An abstract, typed definition of data to communicate. W3C has removed the
message in WSDL 2.0, in which XML Schema types for defining bodies of
inputs, outputs, and faults are referred directly.
Types Types It is a container for data type definition. The XML Schema language (XSD) is
used for this purpose.
8/2/2021 20
WSDL

▪ WSDL is an integral part of UDDI, an XML-based worldwide business registry.


▪ WSDL is the language that UDDI uses.
▪ WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'.

8/2/2021 21
UDDI-Universal Description, Discovery,
and Integration

▪ UDDI is an XML-based standard for describing, publishing, and finding web


services.
▪ UDDI is a specification for a distributed registry of web services.
▪ UDDI is platform independent, open framework.
▪ UDDI can communicate via SOAP, CORBA, and Java RMI Protocol.
▪ UDDI uses WSDL to describe interfaces to web services.
▪ UDDI is seen with SOAP and WSDL as one of the three foundation standards of
web services.
▪ UDDI is an open industry initiative enabling businesses to discover each other and
define how they interact over the Internet.

8/2/2021 22
Types of Web Services

▪ There are two types of web services:


1. RESTful Web Servies
2. SOAP Web Services

8/2/2021 23
RESTful Web Services

▪ REST stands for REpresentational State Transfer.


▪ It is developed by Roy Thomas Fielding who also developed HTTP.
▪ The main goal of RESTful web services is to make web services more effective.
▪ RESTful web services try to define services using the different concepts that are
already present in HTTP. REST is an architectural approach, not a protocol.
▪ It does not define the standard message exchange format.
▪ We can build REST services with both XML and JSON. JSON is more popular format
with REST.
▪ The key abstraction is a resource in REST. A resource can be anything. It can be
accessed through a Uniform Resource Identifier (URI). For example:

8/2/2021 24
RESTful Web Services

▪ The resource has representations like XML, HTML, and JSON. The current state is
captured by representational resource. When we request a resource, we provide
the representation of the resource.
▪ The important methods of HTTP are:
– GET: It reads a resource.
– PUT: It updates an existing resource.
– POST: It creates a new resource.
– DELETE: It deletes the resource.

8/2/2021 25
RESTful Web Services

▪ For example, if we want to perform the following actions in the social media
application, we get the corresponding results.
– POST /users: It creates a user.
– GET /users/{id}: It retrieve the detail of one user.
– GET /users: It retrieve the detail of all users.
– DELETE /users: It delete all users.
– DELETE /users/{id}: It delete a user.
– GET /users/{id}/posts/post_id: It retrieve the detail of a specific post.
– POST / users/{id}/ posts: It creates a post for a user.
– GET /users/{id}/post: Retrieve all posts for a user

8/2/2021 26
Status Codes of HTTP

▪ HTTP also defines the following standard status code:


– 404: RESOURCE NOT FOUND
– 200: SUCCESS
– 201: CREATED
– 401: UNAUTHORIZED
– 500: SERVER ERROR

8/2/2021 27
RESTful Service Constraints

▪ There must be a service producer and service consumer.


▪ The service is stateless.
▪ The service result must be cacheable.
▪ The interface is uniform and exposing resources.

8/2/2021 28
Advantages of RESTful web services

▪ RESTful web services are platform-independent.


▪ It can be written in any programming language and can be executed on any
platform.
▪ It provides different data format like JSON, text, HTML, and XML.
▪ It is fast in comparison to SOAP because there is no strict specification like SOAP.
▪ These are reusable.
▪ These are language neutral.

8/2/2021 29
SOAP Web Services

▪ REST defines an architectural approach whereas SOAP poses a restriction on the


format of the XML. XML transfer data between the service provider and service
consumer. Remember that SOAP and REST are not comparable.
▪ SOAP:
– SOAP acronym for Simple Object Access Protocol. It defines the standard XML
format. It also defines the way of building web services.
– We use Web Service Definition Language (WSDL) to define the format of
request XML and the response XML.

8/2/2021 30
SOAP Web Services

▪ For example, we have requested to access the Todo application from the Facebook
application. The Facebook application sends an XML request to the Todo
application. Todo application processes the request and generates the XML
response and sends back to the Facebook application.

8/2/2021 31
SOAP Web Services

▪ If we are using SOAP web services, we have to use the structure of SOAP.

▪ In the above figure, the SOAP-Envelope contains a SOAP-Header and SOAP-Body. It


contains meta-information needed to identify the request, for example, authentication,
authorization, signature, etc. SOAP-Header is optional. The SOAP-Body contains the
real XML content of request or response. In case of an error, the response server
responds back with SOAP-Fault.

8/2/2021 32
Code Snippet for more clear
understanding

▪ Let's understand the SOAP XML request and response structure.


▪ XML Request
<Envelop xmlns=?http://schemas.xmlsoap.org/soap/envelop/?>
<Body>
<getCourseDetailRequest xmlns=?http://udemy.com/course?>
<id>course1</id>
<getCourseDetailRequest>
</Body>
</Envelop>

8/2/2021 33
XML Response

<SOAP-ENV:Envelope xmlns:SOAP-
ENV=?http://schemas.xmlsoap.org/soap/envelope/?>
<SOAP-ENV:Header /> <!?empty header-->
<SOAP-ENV:Body> <!?body begin-->
<ns2:getCourseDetailsResponse xmlns:ns2=?http://in28mi> <!--content of
the response-->
<ns2:course>
<ns2:id>Course1</ns2:id>
<ns2:name>Spring<ns2:name>
<ns2:description>10 Steps</ns1:description>
</ns2:course>
</ns2:getCourseDetailResponse>
</SOAP-ENV:Body> <!?body end-->
</SOAP-ENV:Envelope>

8/2/2021 34
Points to remember

▪ SOAP defines the format of request and response.


▪ SOAP does not pose any restriction on transport. We can either use HTTP or MQ
for communication.
▪ In SOAP, service definition typically done using Web Service Definition Language
(WSDL). WSDL defines Endpoint, All Operations, Request Structure, and Response
Structure.
▪ The Endpoint is the connection point where HTML or ASP pages are exposed. It
provides the information needed to address the Web Service endpoint. The
operations are the services that are allowed to access. Request structure defines
the structure of the request, and the response structure defines the structure of the
response.

8/2/2021 35
SOAP vs REST Web Services

No. SOAP REST


1) SOAP is a protocol. REST is an architectural style.
2) SOAP stands for Simple Object Access REST stands for REpresentational State Transfer.
Protocol.
3) SOAP can't use REST because it is a protocol. REST can use SOAP web services because it is a
concept and can use any protocol like HTTP, SOAP.
4) SOAP uses services interfaces to expose the REST uses URI to expose business logic.
business logic.
5) JAX-WS is the java API for SOAP web services. JAX-RS is the java API for RESTful web services.
6) SOAP defines standards to be strictly followed. REST does not define too much standards like SOAP.
7) SOAP requires more bandwidth and resource REST requires less bandwidth and resource than
than REST. SOAP.
8) SOAP defines its own security. RESTful web services inherits security
measures from the underlying transport.
9) SOAP permits XML data format only. REST permits different data format such as Plain
text, HTML, XML, JSON etc.
10) SOAP is less preferred than REST. 8/2/2021
REST more preferred than SOAP. 36
Summary

▪ To summarize, a complete web service is, therefore, any service that −


– Is available over the Internet or private (intranet) networks
– Uses a standardized XML messaging system
– Is not tied to any one operating system or programming language
– Is self-describing via a common XML grammar
– Is discoverable via a simple find mechanism

8/2/2021 37
Overview of XML in web services

▪ Different books and different organizations provide different definitions to Web


Services. Some of them are listed here.
– A web service is any piece of software that makes itself available over the
internet and uses a standardized XML messaging system.
– XML is used to encode all communications to a web service. For example, a
client invokes a web service by sending an XML message, then waits for a
corresponding XML response.
– As all communication is in XML, web services are not tied to any one operating
system or programming language—Java can talk with Perl; Windows
applications can talk with Unix applications.

8/2/2021 38
How Does a Web Service Work?

▪ A web service enables communication among various applications by using open


standards such as HTML, XML, WSDL, and SOAP. A web service takes the help of −
– XML to tag the data
– SOAP to transfer a message
– WSDL to describe the availability of service.
– You can build a Java-based web service on Solaris that is accessible from your
Visual Basic program that runs on Windows.
– You can also use C# to build new web services on Windows that can be invoked
from your web application that is based on JavaServer Pages (JSP) and runs on
Linux.

8/2/2021 39
XML 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

8/2/2021 40
Interoperability has Highest Priority

▪ When all major platforms could access the Web using Web browsers, different
platforms couldn't interact. For these platforms to work together, Web-
applications were developed.
▪ Web-applications are simply applications that run on the web. These are built
around the Web browser standards and can be used by any browser on any
platform.

8/2/2021 41
Web Services take Web-applications to
the Next Level

▪ By using Web services, your application can publish its function or message to the
rest of the world.
▪ Web services use XML to code and to decode data, and SOAP to transport it (using
open protocols).
▪ With Web services, your accounting department's Win 2k server's billing system
can connect with your IT supplier's UNIX server.

8/2/2021 42
Web Services have Two Types of Uses

▪ Reusable application-components.
– There are things applications need very often. So why make these over and over
again?
– Web services can offer application-components like: currency conversion,
weather reports, or even language translation as services.
▪ Connect existing software.
– Web services can help to solve the interoperability problem by giving different
applications a way to link their data.
– With Web services you can exchange data between different applications and
different platforms.
– Any application can have a Web Service component.
– Web Services can be created regardless of programming language.

8/2/2021 43
XML WSDL
WSDL Documents

▪ An WSDL document describes a web service. It specifies the location of the service,
and the methods of the service, using these major elements:

Element Description
<types> Defines the (XML Schema) data types used by the web service
<message> Defines the data elements for each operation
<portType> Describes the operations that can be performed and the messages
involved.
<binding> Defines the protocol and data format for each port type

8/2/2021 45
The main structure of a WSDL document looks like this:

<definitions>

<types>
data type definitions........
</types>

<message>
definition of the data being communicated....
</message>

<portType>
set of operations......
</portType>

<binding>
protocol and data format specification....
</binding>

</definitions>
The <portType> Element

▪ The <portType> element defines a web service, the operations that can be
performed, and the messages that are involved.
▪ The request-response type is the most common operation type, but WSDL defines
four types:

Type Definition
One-way The operation can receive a message but will not return a response
Request-response The operation can receive a request and will return a response
Solicit-response The operation can send a request and will wait for a response
Notification The operation can send a message but will not wait for a response

8/2/2021 47
WSDL One-Way Operation

A one-way operation example:

<message name="newTermValues">
<part name="term" type="xs:string"/>
<part name="value" type="xs:string"/>
</message>

<portType name="glossaryTerms">
<operation name="setTerm">
<input name="newTerm" message="newTermValues"/>
</operation>
</portType >
SOAP Web Services

▪ SOAP is an XML-based protocol for accessing web services over HTTP. It has some
specification which could be used across all applications.
▪ SOAP is known as the Simple Object Access Protocol, but in later times was just
shortened to SOAP v1.2. SOAP is a protocol or in other words is a definition of how
web services talk to each other or talk to client applications that invoke them.
▪ SOAP was developed as an intermediate language so that applications built on
various programming languages could talk easily to each other and avoid the
extreme development effort.

8/2/2021 49
Advantages of Soap Web Services

▪ WS Security:
– SOAP defines its own security known as WS Security.
▪ Language and Platform independent:
– SOAP web services can be written in any programming language and executed
in any platform.
▪ It works on the HTTP protocol –SOAP works on the HTTP protocol, which is the
default protocol used by all web applications. Hence, there is no sort of
customization which is required to run the web services built on the SOAP protocol
to work on the World Wide Web.

8/2/2021 50
Advantages of Soap Web Services

SOAP is the protocol used for data interchange between applications. Below are
some of the reasons as to why SOAP is used.
▪ When developing SOAP based Web services, you need to have some of language
which can be used for web services to talk with client applications. SOAP is the
perfect medium which was developed in order to achieve this purpose. This
protocol is also recommended by the W3C consortium which is the governing body
for all web standards.
▪ SOAP is a light-weight protocol that is used for data interchange between
applications. Note the keyword 'light.' Since SOAP programming is based on the
XML language, which itself is a light weight data interchange language, hence
SOAP as a protocol that also falls in the same category.

8/2/2021 51
Disadvantages of Soap Web Services

▪ Slow:
– SOAP uses XML format that must be parsed to be read. It defines many
standards that must be followed while developing the SOAP applications. So it is
slow and consumes more bandwidth and resource.
▪ WSDL dependent:
– SOAP uses WSDL and doesn't have any other mechanism to discover the
service.

8/2/2021 52
SOAP Building Blocks

▪ The SOAP specification defines something known as a "SOAP message" which is


what is sent to the web service and the client application.
▪ The below diagram of SOAP architecture shows the various building blocks of a
SOAP Message.

8/2/2021 53
SOAP Message Building Blocks

▪ The SOAP message is nothing but a mere XML document which has the below
components.
▪ An Envelope element that identifies the XML document as a SOAP message – This
is the containing part of the SOAP message and is used to encapsulate all the
details in the SOAP message. This is the root element in the SOAP message.
▪ A Header element that contains header information – The header element can
contain information such as authentication credentials which can be used by the
calling application. It can also contain the definition of complex types which could
be used in the SOAP message. By default, the SOAP message can contain
parameters which could be of simple types such as strings and numbers, but can
also be a complex object type.

8/2/2021 54
A simple SOAP service example of a complex type is shown below.

Suppose we wanted to send a structured data type which had a combination of a "Tutorial Name" and a
"Tutorial Description," then we would define the complex type as shown below.

The complex type is defined by the element tag <xsd:complexType>. All of the required elements of the
structure along with their respective data types are then defined in the complex type collection.

<xsd:complexType>
<xsd:sequence>
<xsd:element name="Tutorial Name" type="string"/>
<xsd:element name="Tutorial Description" type="string"/>
</xsd:sequence>
</xsd:complexType>
A Body element that contains call and response information – This element is what contains the actual data
which needs to be sent between the web service and the calling application. Below is an SOAP web service
example of the SOAP body which actually works on the complex type defined in the header section. Here is
the response of the Tutorial Name and Tutorial Description that is sent to the calling application which calls this
web service.

<soap:Body>
<GetTutorialInfo>
<TutorialName>Web Services</TutorialName>
<TutorialDescription>All about web services</TutorialDescription>
</GetTutorialInfo>
</soap:Body>
SOAP Message Structure

▪ One thing to note is that SOAP messages are normally auto-generated by the web
service when it is called.
▪ Whenever a client application calls a method in the web service, the web service
will automatically generate a SOAP message which will have the necessary details
of the data which will be sent from the web service to the client application.
▪ As discussed earlier, a simple SOAP Message has the following elements –
– The Envelope element
– The header element and
– The body element
– The Fault element (Optional)

8/2/2021 57
Example of SOAP Message Structure

▪ Let's look at an example below of a simple SOAP message and see what element
actually does.

8/2/2021 58
Example of SOAP Message Structure

1. As seen from the above SOAP message, the first part of the SOAP message is the
envelope element which is used to encapsulate the entire SOAP message.
2. The next element is the SOAP body which contains the details of the actual message.
3. Our message contains a web service which has the name of "Guru99WebService".
4. The "Guru99Webservice" accepts a parameter of the type 'int' and has the name of
TutorialID.
▪ Now, the above SOAP message will be passed between the web service and the client
application.
▪ You can see how useful the above information is to the client application. The SOAP
message tells the client application what is the name of the Web service, and also what
parameters it expects and also what is the type of each parameter which is taken by the
web service.

8/2/2021 59
SOAP Envelope Element

▪ The first bit of the building block is the SOAP Envelope.


▪ The SOAP Envelope is used to encapsulate all of the necessary details of the SOAP
messages, which are exchanged between the web service and the client
application.
▪ The SOAP envelope element is used to indicate the beginning and end of a SOAP
message. This enables the client application which calls the web service to know
when the SOAP message ends.
▪ The following points can be noted on the SOAP envelope element.

8/2/2021 60
SOAP Envelope Element

▪ Every SOAP message needs to have a root Envelope element. It is absolutely


mandatory for SOAP message to have an envelope element.
▪ Every Envelope element needs to have at least one soap body element.
▪ If an Envelope element contains a header element, it must contain no more than
one, and it must appear as the first child of the Envelope, before the body element.
▪ The envelope changes when SOAP versions change.
▪ A v1.1-compliant SOAP processor generates a fault upon receiving a message
containing the v1.2 envelope namespace.
▪ A v1.2-compliant SOAP processor generates a Version Mismatch fault if it receives
a message that does not include the v1.2 envelope namespace.

8/2/2021 61
Example of SOAP API

▪ Below is an SOAP API example of version 1.2 of the SOAP envelope element.
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope"
SOAP-ENV:encodingStyle=" http://www.w3.org/2001/12/soap-encoding">
<soap:Body>
<Guru99WebService xmlns="http://tempuri.org/">
<TutorialID>int</TutorialID>
</Guru99WebService>
</soap:Body>
</SOAP-ENV:Envelope>

8/2/2021 62
The Fault message

▪ When a request is made to a SOAP web service, the response returned can be of
either 2 forms which are a successful response or an error response. When a
success is generated, the response from the server will always be a SOAP message.
But if SOAP faults are generated, they are returned as "HTTP 500" errors.
▪ The SOAP Fault message consists of the following elements.

8/2/2021 63
SOAP Fault message elements

1. <faultCode>- This is the code that designates the code of the error. The fault code
can be either of any below values
– SOAP-ENV:VersionMismatch – This is when an invalid namespace for the SOAP Envelope element is
encountered.
– SOAP-ENV:MustUnderstand - An immediate child element of the Header element, with the
mustUnderstand attribute set to "1", was not understood.
– SOAP-ENV:Client - The message was incorrectly formed or contained incorrect information.
– SOAP-ENV:Server - There was a problem with the server, so the message could not proceed.

8/2/2021 64
SOAP Fault message elements

2. <faultString> - This is the text message which gives a detailed description of the
error.
3. <faultActor> (Optional)- This is a text string which indicates who caused the fault.
4. <detail>(Optional) - This is the element for application-specific error messages.
So the application could have a specific error message for different business logic
scenarios.

8/2/2021 65
Example for Fault Message

An example of a fault message is given below. The error is generated if the scenario wherein the client tries to use a
method called TutorialID in the class GetTutorial.

The below fault message gets generated in the event that the method does not exist in the defined class.

<?xml version='1.0' encoding='UTF-8'?>


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode>
<faultstring xsi:type="xsd:string">
Failed to locate method (GetTutorialID) in class (GetTutorial)
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Output:
When you execute the above code, it will show the error like "Failed to locate method (GetTutorialID) in class
(GetTutorial)"
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.
▪ Now in this SOAP API tutorial, 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.

8/2/2021 67
SOAP Communication Model

▪ 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 below communication model has the following serious limitations

8/2/2021 68
Limitations

▪ 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.
▪ 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.
▪ 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.

8/2/2021 69
SOAP Communication Model

▪ To overcome all of the limitations cited above, SOAP would then use the below
communication model

8/2/2021 70
SOAP Communication Model

▪ 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.
▪ 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.

8/2/2021 71
Summary

▪ SOAP is a protocol which is used to interchange data between applications which are
built on different programming languages.
▪ SOAP is built upon the XML specification and works with the HTTP protocol. This makes
it a perfect for usage within web applications.
▪ The SOAP building blocks consist of a SOAP Message. Each SOAP message consists of
an envelope element, a header, and a body element.
▪ The envelope element is the mandatory element in the SOAP message and is used to
encapsulate all of the data in the SOAP message.
▪ The header element can be used to contain information such as authentication
information or the definition of complex data types.
▪ The body element is the main element which contains the definition of the web
methods along with any parameter information if required.

8/2/2021 72
Building Web Services with JAX-WS

▪ Java API for XML Web Services (JAX-WS) is a technology for building web services
and clients that communicate using XML.
▪ JAX-WS allows developers to write message-oriented as well as Remote Procedure
Call-oriented (RPC-oriented) web services.
▪ In JAX-WS, a web service operation invocation is represented by an XML-based
protocol, such as SOAP.
▪ The SOAP specification defines the envelope structure, encoding rules, and
conventions for representing web service invocations and responses. These calls
and responses are transmitted as SOAP messages (XML files) over HTTP.

8/2/2021 73
Service-oriented computing

▪ Service-oriented computing organizes distributed systems in terms of services,


which represent the major abstraction for building systems.
▪ Service orientation expresses applications and software systems as aggregations
of services that are coordinated within a service-oriented architecture (SOA).
▪ Even though there is no designed technology for the development of service-
oriented software systems, Web services are the de facto approach for developing
SOA.
▪ Web services, the fundamental component enabling cloud computing systems,
leverage the Internet as the main interaction channel between users and the
system.

8/2/2021 74
What is a service?

▪ A service encapsulates a software component that provides a set of coherent and


related functionalities that can be reused and integrated into bigger and more
complex applications.
▪ The term service is a general abstraction that encompasses several different
implementations using different technologies and protocols. Don Box identifies
four major characteristics that identify a service:

8/2/2021 75
1. Boundaries are explicit

▪ A service-oriented application is generally composed of services that are spread


across different domains, trust authorities, and execution environments.

8/2/2021 76
2. Services are autonomous.

▪ Services are components that exist to offer functionality and are aggregated and
coordinated to build more complex system.
▪ They are not designed to be part of a specific system, but they can be integrated in
several software systems, even at the same time.

8/2/2021 77
3. Services share schema and contracts,
not class or interface definitions

▪ Services are not expressed in terms of classes or interfaces, as happens in object-


oriented systems, but they define themselves in terms of schemas and contracts.
▪ A service advertises a contract describing the structure of messages it can send
and/or receive and additional constraint-if any-on their ordering.
▪ Because they are not expressed in terms of types and classes, services are more
easily consumable in wider and heterogeneous environments.
▪ Technologies such as XML and SOAP provide the appropriate tools to support such
features rather than class definition or an interface declaration.

8/2/2021 78
4. Services compatibility is determined
based on policy.

▪ Service orientation separates structural compatibility from semantic compatibility.


Structural compatibility is based on contracts and schema and can be validated or
enforced by machine-based techniques.
▪ Semantic compatibility is expressed in the form of policies that define the
capabilities and requirements for a service.
▪ Policies are organized in terms of expressions that must hold true to enable the
normal operation of a service.

8/2/2021 79
Service-oriented architecture (SOA)

▪ SOA is an architectural style supporting service orientation.


▪ It organizes a software system into a collection of interacting services.
▪ SOA encompasses a set of design principles that structure system development
and provide means for integrating components into a coherent and decentralized
system.
▪ SOA-based computing packages functionalities into a set of interoperable services,
which can be integrated into different software systems belonging to separate
business domains.

8/2/2021 80
Roles within SOA

▪ There are two major roles within SOA:


– the service provider and
– the service consumer.
▪ The service provider is the maintainer of the service and the organization that
makes available one or more services for others to use.
▪ To advertise services, the provider can publish them in a registry, together with a
service contract that specifies the nature of the service, how to use it, the
requirements for the service, and the fees charged.
▪ The service consumer can locate the service metadata in the registry and develop
the required client components to bind and use the service. Service providers and
consumers can belong to different organization bodies or business domains.

8/2/2021 81
SOA

▪ SOA provides a reference model for architecting several software systems,


especially enterprise business applications and systems.
▪ In this context, interoperability, standards, and service contracts play a
fundamental role.
▪ In particular, the following guiding principles, which characterize SOA platforms,
are winning features within an enterprise context:

8/2/2021 82
SOA

▪ Standardized service contract:


– Services adhere to a given communication agreement, which is specified
through one or more service description documents.
▪ Loose coupling:
– Services are designed as self-contained components, maintain relationships that
minimize dependencies on other services, and only require being aware of each
other.
▪ Abstraction:
– A service is completely defined by service contracts and description documents.
They hide their logic, which is encapsulated within their implementation.

8/2/2021 83
SOA

▪ Reusability:
– Designed as components, services can be reused more effectively, thus reducing
development time and the associated costs.
▪ Autonomy:
– Services have control over the logic they encapsulate and, from a service
consumer point of view, there is no need to know about their implementation.

8/2/2021 84
Web services

▪ Web services are the prominent technology for implementing SOA systems and
applications.
▪ They leverage Internet technologies and standards for building distributed
systems. Several aspects make Web services the technology of choice for SOA.
▪ First, they allow for interoperability across different platforms and programming
languages.
▪ Second, they are based on well-known and vendor-independent standards such as
HTTP, SOAP, XML, and WSDL .
▪ Third, they provide an intuitive and simple way to connect heterogeneous software
systems, enabling the quick composition of services in a distributed environment

8/2/2021 85
Web services

▪ Finally, they provide the features required by enterprise business applications to be


used in an industrial environment.
▪ They define facilities for enabling service discovery, which allows system architects
to more efficiently compose SOA applications, and service metering to assess
whether a specific service complies with the contract between the service provider
and the service consumer.

8/2/2021 86
Concept behind a Web service

▪ The concept behind a Web service is very simple. Using as a basis the object-
oriented abstraction, a Web service exposes a set of operations that can be invoked
by leveraging Internet-based protocols.
▪ Method operations support parameters and return values in the form of complex
and simple types.
▪ The semantics for invoking Web service methods is expressed through
interoperable standards such as XML and WSDL, which also provide a complete
framework for expressing simple and complex types in a platform-independent
manner.
▪ Web services are made accessible by being hosted in a Web server; therefore,
HTTP is the most popular transport protocol used for interacting with Web
services. Below figure describes the common-use case scenarios for Web services.

8/2/2021 87
Web Service Interaction

▪ A Web services interaction reference scenario.

8/2/2021 88
Web Service Development Lifecycle

▪ Web services development lifecycle (SDLC), or service-oriented design and


development, is a highly iterative and continuous approach to developing,
implementing, deploying, and maintaining Web services in which feedback is
continuously cycled to and from phases in iterative steps of refinement.
▪ Managing the entire services lifecycle – including analyzing, identifying, designing,
developing, deploying, finding, applying, evolving, and maintaining services.

8/2/2021 89
WSDL

▪ Establishing a platform and programming model, which includes connecting,


deploying, and managing services within a specific run-time platform.
▪ Adopting best practices and tools for architecting services-oriented solutions in
repeatable, predictable ways that deal with changing business needs.
▪ This includes mining existing applications to discover potential services,
repurposing existing assets and functionality to extend their utility and make those
capabilities accessible as services, creating new services, and “wiring” together
services by connecting behavior exposed through their interfaces.
▪ Delivering high-quality workable service-oriented solutions that respect QoS
requirements.

8/2/2021 90
Phases of SDLC

▪ The phases in the SDLC methodology encompass


– planning,
– analysis,
– design,
– construction.
▪ It is a premise of the lifecycle that these phases are traversed iteratively and that
feedback is cycled to and from phases in iterative steps of refinement and that the
methodology may actually be built using a blend of forward- and reverse-
engineering techniques or other means to facilitate the needs of the business.

8/2/2021 91
Web site Planning

▪ Involves the identification of the Web site goals or purpose. The question to ask is:
What is the purpose of this Web site?
▪ In addition to understanding the Web site purpose, you should also ask: Who will
use the Website? or knowing the target audience in terms of: age, gender,
computer literacy, etc.
▪ Understanding the computing environment will allow the designer to know what
type of Technologies to use.
▪ The last question is to ask who will provide the information included in the Web
site.

8/2/2021 92
Web Site Analysis

▪ During this phase, the Web designer needs to make decisions about the Web site
content and functionality.
▪ It includes a detailed analysis of the content of the Website in terms information
covered, processing required, etc.

8/2/2021 93
Web Site design and Development

▪ After, the purpose of the Website has been found and the content has been
defined, we need to organize the content of the Website.
▪ Many ways to organize the Website exists. Here are some general pointers:

8/2/2021 94
Elements Purpose
Titles Use simple titles that clearly explain the purpose of the page
Headings Use Headings to separate main topics
Horizontal rules Use horizontal rules to separate main topics
Paragraphs Use paragraphs to help divide large amount of data
Lists Utilize list. Numbered or bullet when appropriate
Page Length Maintain suitable Web page lengths; about one or two pages
are adequate
Information Emphasize the most important information by placing it at the
top of a Web page
Others ✓ Incorporate a contact e-mail address
✓ Include the date of the last modification
Web site layouts

▪ Websites are designed using any of several different types of layouts, including
linear, hierarchical, and Webbed.
▪ Each layout links, or connects, the Web pages in a different structure to define how
users navigate through the site and view the Web pages.
▪ You should select a layout for your Web site based on how users will most easily
navigate through the site to complete tasks and view the Web site contents.
▪ A linear Web site layout connects Web pages in a straight line. A linear Web site
layout connects Web pages in a straight line.
▪ A linear Web is appropriate if the information on the Web pages should be read in a
specific order.

8/2/2021 96
Web site layouts

▪ A hierarchical Web site layout connects Web pages in a tree-like structure. A


hierarchical Web site layout works well on a site with a main index or table of
contents page that links to all other Web pages. With this layout, the main index
page would display general information and secondary pages include information
that is more detailed.
▪ A Webbed Web site layout has no set structure. A Webbed Web site layout works
best on Web sites with information that does not need to be read in a specific order
and with many navigation options that users can select.

8/2/2021 97
Structure Example

8/2/2021 98
Web site testing

▪ A Web site should be tested at various stages of the Web design and development. This
testing should include a review of page content, functionality and usability. Some basic
steps to test content and functionality are:
▪ Reviewing for accurate spelling and proofreading content including page titles.
▪ Checking links to ensure that they are not broken and are linked correctly
▪ Checking graphics to confirm they display properly and are linked correctly
▪ Testing forms and other interactive page elements
▪ Testing pages to check for speed of loading on lower speed connection
▪ Printing each page to check how pages print
▪ Testing each Web in several different browser types and versions to verify they display
correctly

8/2/2021 99
Site Implementation and Maintenance

▪ Once, the Web site has been implemented, its maintenance will include updating
the information content by removing the outdated one and putting in the new one.
▪ Periodical checking of the links is also necessary to ensure that they are still active.
▪ Finally, Website monitoring is another key aspect of maintenance. Usually, the Web
servers that host the Web sites keep logs about Web site usage.
▪ A log is the file that lists all the Web pages that have been requested from the Web
site.
▪ Analyzing the logs allows you to determine the number of visitors to your site and
the browser types and versions they are using, as well as their connection speeds,
most commonly requested pages.

8/2/2021 100
Cookies

▪ Internet cookies are very small files that are downloaded from a Web server to a
Web browser. Cookies are embedded in the HTML code related to downloading
requested pages from a Web site.
▪ When a Web browser first asks for a file from a Web server, the server creates a
cookie containing information about the request and sends the cookie to the
browser along with the requested file.
▪ The next time a request is made from the browser to the server, the cookie is sent
to the server along with the request. When the server returns the requested file, an
updated cookie is also returned.

8/2/2021 101
Service Endpoint Interface

Use:
▪ When creating an inside-out Web service, you can use a service endpoint interface
(SEI) to expose some or all methods of the implementation bean as Web service
methods.
▪ An SEI is a Java interface which declares the methods of the implementation bean
a consumer application can invoke on the Web service.
▪ It represents the Web service contract definition and enables you to separate that
contract definition from the Web service implementation.
▪ The use of an SEI to create a Web service allows you to develop the
implementation class and the Web service consumer application in parallel and
independently in time based on the SEI.

8/2/2021 102
Service Implementation Bean (SIB),

▪ A Service Implementation Bean (SIB), is a term used in Java Platform, Enterprise


Edition, for a Java object implementing a web service. It can be either a POJO or a
Stateless Session EJB. The Java interface of an SIB is called a Service Endpoint
Interface (SEI).

8/2/2021 103
Google Classroom code for
“Web Services”

▪ Join the Google Classroom by Using following Code:

57ue75w

8/2/2021 104
Thank You!!!Any Query?
[email protected]
Shivkumar Chandey
(+91 9987389441)
Scan QR Code to connect
on LinkedIn

8/2/2021 105

You might also like