Web SErvices Complete PDF-merged
Web SErvices Complete PDF-merged
[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
▪ 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?
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
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
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
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
10/16/2021 54
RESTful Service Constraints
10/16/2021 55
Advantages of RESTful web services
10/16/2021 56
The core architectural elements of a
RESTful system
10/16/2021 57
Core elements
10/16/2021 58
Resources
10/16/2021 59
URI
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
10/16/2021 65
Hypermedia as the Engine of Application
State
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
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
10/16/2021 71
Swagger
10/16/2021 72
Swagger framework
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
10/16/2021 78
JSON message format and tools and
frameworks around JSON
JSON
10/16/2021 80
JSON
10/16/2021 81
Uses of JSON
10/16/2021 82
Characteristics of JSON
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
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
10/16/2021 101
Three Ways of Processing 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
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
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
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”
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
▪ 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?
10/10/2021 6
A few sample scenarios include:
10/10/2021 7
More on WCF
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
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
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
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
10/10/2021 20
Extensibility
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
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
10/10/2021 26
Contracts
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
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
10/10/2021 31
SOAP
10/10/2021 32
Advantages of WCF
10/10/2021 33
Advantages of WCF
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
10/10/2021 42
Service Runtime
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
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
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
10/10/2021 55
Google Classroom code for
“Web Services”
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
▪ 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?
8/2/2021 6
Introduction to Web Services
8/2/2021 7
Why do you need a Web Service?
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
8/2/2021 10
Moreover, A Web service can be
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
8/2/2021 13
Web Service Characteristics
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
8/2/2021 17
SOAP-Simple Object Access Protocol
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
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
8/2/2021 21
UDDI-Universal Description, Discovery,
and Integration
8/2/2021 22
Types of Web Services
8/2/2021 23
RESTful Web Services
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
8/2/2021 27
RESTful Service Constraints
8/2/2021 28
Advantages of RESTful web services
8/2/2021 29
SOAP Web Services
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.
8/2/2021 32
Code Snippet for more clear
understanding
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
8/2/2021 35
SOAP vs REST Web Services
8/2/2021 37
Overview of XML in web services
8/2/2021 38
How Does a Web Service Work?
8/2/2021 39
XML 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
<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
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
8/2/2021 60
SOAP Envelope Element
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.
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
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
8/2/2021 74
What is a service?
8/2/2021 75
1. Boundaries are explicit
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
8/2/2021 78
4. Services compatibility is determined
based on policy.
8/2/2021 79
Service-oriented architecture (SOA)
8/2/2021 80
Roles within SOA
8/2/2021 81
SOA
8/2/2021 82
SOA
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
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
8/2/2021 88
Web Service Development Lifecycle
8/2/2021 89
WSDL
8/2/2021 90
Phases of SDLC
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
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),
8/2/2021 103
Google Classroom code for
“Web Services”
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