Web Services Notes
Web Services Notes
asp
URI = Uniform Resource Identifier : Names and Addresses of Objects on the Network as used in
the World-Wide Web
URL
URN
One can classify URIs as locators (URLs), or as names (URNs), or as both. A Uniform
Resource Name (URN) functions like a person's name, while a Uniform Resource Locator
(URL) resembles that person's street address. In other words: the URN defines an item's
identity, while the URL provides a method for finding it.
The ISBN system for uniquely identifying books provides a typical example of the use of
URNs. ISBN 0486275574 (urn:isbn:0-486-27557-4) cites unambiguously a specific edition of
Shakespeare's play Romeo and Juliet. To gain access to this object and read the book, one
needs its location: a URL address. A typical URL for this book on a Unix-like operating
system would be a file path such as file:///home/username/RomeoAndJuliet.pdf,
identifying the electronic book saved in a file on a local hard disk. So URNs and URLs have
complementary purposes.
Examples for web services
A "Weather Web Service" is probably one of the most typical examples of a simple web
service.
The terms Web service and web server should not be confused.
Web service is an addition to the web servers.
XML
External data representation and marshalling of messages exchanged between clients and
web services is done in XML.
A web service is identified by a URI and can be accessed by clients using messages formatted
in XML.
Before you continue you should have a basic understanding of the following:
HTML
JavaScript
If you want to study these subjects first, find the tutorials on our Home page.
What is XML?
XML was designed to transport and store data, with focus on what data is
HTML was designed to display data, with focus on how data looks
Maybe it is a little hard to understand, but XML does not DO anything. XML was created to
structure, store, and transport information.
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The note above is quite self descriptive. It has sender and receiver information, it also has a
heading and a message body.
But still, this XML document does not DO anything. It is just information wrapped in tags.
Someone must write a piece of software to send, receive or display it.
The tags in the example above (like <to> and <from>) are not defined in any XML standard.
These tags are "invented" by the author of the XML document.
The tags used in HTML are predefined. HTML documents can only use tags defined in the
HTML standard (like <p>, <h1>, etc.).
XML allows the author to define his/her own tags and his/her own document structure.
XML is Not a Replacement for HTML
It is important to understand that XML is not a replacement for HTML. In most web
applications, XML is used to transport data, while HTML is used to format and display the
data.
SOAP
SOAP is used to encapsulate messages and transmit them over HTTP or another protocol, for
example, TCP or SMTP.
In the middleware, a naming or a directory service allow clients to find out services.
SOAP is a simple XML-based protocol to let applications exchange information over HTTP.
What is SOAP?
Why SOAP?
Today's applications communicate using Remote Procedure Calls (RPC) between objects like
DCOM and CORBA, but HTTP was not designed for this. RPC represents a compatibility
and security problem; firewalls and proxy servers will normally block this kind of traffic.
A better way to communicate between applications is over HTTP, because HTTP is supported
by all Internet browsers and servers. SOAP was created to accomplish this.
SOAP
Envelope
Header
Body
http://www.tutorialspoint.com/soap/what_is_soap.htm
Web service: First and foremost, we have our Web service. As we have seen, this is basically a piece
of software that exposes a set of operations. For example, if we are implementing our Web service in
Java, our service will be a Java class (and the operations will be implemented as Java methods).
Obviously, we want a set of clients to be able to invoke those operations. However, our Web service
implementation knows nothing about how to interpret SOAP requests and how to create SOAP
responses.
WEB (HTTP) Server: This is more commonly called a 'Web server'. It is a piece of software that knows
how to handle HTTP messages. A good example is the Apache HTTP Server, one of the most popular
web servers in the Internet.
SOAP engine: This is a piece of software that knows how to handle SOAP requests and responses. In
practice, it is more common to use a generic SOAP engine than to actually generate server stubs for
each individual Web service (note, however, that we still need client stubs for the client). One good
example of a SOAP engine is Apache Axis (this is, in fact, the SOAP engine used by the Globus
Toolkit). However, the functionality of the SOAP engine is usually limited to manipulating SOAP.
Application server: This is a piece of software that provides a 'living space' for applications
that must be accessed by different clients. The SOAP engine runs as an application inside the
application server. A good example is the Jakarta Tomcat server, a Java Servlet and Java
ServerPages container that is frequently used with Apache Axis and the Globus Toolkit.
Many application servers already include some HTTP functionality, so we can have Web
services up and running by installing a SOAP engine and an application server. However,
when an application server lacks HTTP functionality, we also need a Web server.
So, what exactly are SOAP and WSDL? They're essential parts of the Web Services
Architecture:
Service Processes: This part of the architecture generally involves more than one Web
service. For example, discovery belongs in this part of the architecture, since it allows
us to locate one particular service from among a collection of Web services.
Service Description: One of the most interesting features of Web Services is that they
are self-describing. This means that, once you've located a Web Service, you can ask it
to 'describe itself' and tell you what operations it supports and how to invoke it. This is
handled by the Web Services Description Language (WSDL).
Service Invocation: Invoking a Web Service (and, in general, any kind of distributed
service such as a CORBA object or an Enterprise Java Bean) involves passing
messages between the client and the server. SOAP (Simple Object Access Protocol)
specifies how we should format requests to the server, and how the server should
format its responses. In theory, we could use other service invocation languages (such
as XML-RPC, or even some ad hoc XML language). However, SOAP is by far the
most popular choice for Web Services.
Transport: Finally, all these messages must be transmitted somehow between the
server and the client. The protocol of choice for this part of the architecture is HTTP
(HyperText Transfer Protocol), the same protocol used to access conventional web
pages on the Internet. Again, in theory we could be able to use other protocols, but
HTTP is currently the most used one.
OK, now that you have an idea of what Web Services are, you are probably anxious to start
programming Web Services right away. Before you do that, you might want to know how
Web Services-based applications are structured. If you've ever used CORBA or RMI, this
structure will look pretty familiar.
First of all, you should know that despite having a lot of protocols and languages floating
around, Web Services programmers usually only have to concentrate on writing code in their
favorite programming language and, in some cases, in writing WSDL. SOAP code, on the
other hand, is always generated and interpreted automatically for us. Once we've reached a
point where our client application needs to invoke a Web Service, we delegate that task on a
piece of software called a stub. The good news is that there are plenty of tools available that
will generate stubs automatically for us, usually based on the WSDL description of the Web
Service.
Figure 1.7. Client and server stubs are generated from the WSDL file
Using stubs simplifies our applications considerably. We don't have to write a complex client
program that dynamically generates SOAP requests and interprets SOAP responses (and
similarly for the server side of our application). We can simply concentrate on writing the
client and/or server code, and leave all the dirty work to the stubs (which, again, we don't
even have to write ourselves... they can be generated automatically from the WSDL
description of a web service).
The stubs are generally generated only once. In other words, you shouldn't interpret the
"Typical Web Service Invocation" figure (above) as saying that we go through the discovery
process every single time we want to invoke a Web service, and generate the client stubs
every time we want to invoke the service. In general, we only go through the discovery step
once, then generate the stubs once (based on the WSDL of the service we've discovered) and
then reuse the stubs as many times as we want (unless the maintainers of the Web service
decide to change the service's interface and, thus, its WSDL description). Of course, there are
more complex invocation scenarios, but for now the one we've described is more than enough
to understand how Web services work.
So, let's suppose that we've already located the Web Service we want to use (either because
we consulted a discovery service, or because the Web service URI was given to us), and
we've generated the client stubs from the WSDL description. What exactly happens when we
want to invoke a Web service operation from a program?
1. Whenever the client application needs to invoke the Web Service, it will really call the
client stub. The client stub will turn this 'local invocation' into a proper SOAP request.
This is often called the marshaling or serializing process.
2. The SOAP request is sent over a network using the HTTP protocol. The server
receives the SOAP requests and hands it to the server stub. The server stub will
convert the SOAP request into something the service implementation can understand
(this is usually called unmarshaling or deserializing)
3. Once the SOAP request has been deserialized, the server stub invokes the service
implementation, which then carries out the work it has been asked to do.
4. The result of the requested operation is handed to the server stub, which will turn it
into a SOAP response.
5. The SOAP response is sent over a network using the HTTP protocol. The client stub
receives the SOAP response and turns it into something the client application can
understand.
6. Finally the application receives the result of the Web Service invocation and uses it.
There are different method for providing web services but the most common are
SOAP,
XML-RPC and
REST .
Google is consistent in implementing their web services using SOAP, with the exception of Blogger,
which uses XML-RPC.
All of the major webservices on the Internet now use REST: Twitter, Yahoo’s web services use REST,
others include Flickr, del.icio.us, pubsub, bloglines, technorati, and several others. Both eBay and
Amazon have web services for both REST and SOAP.
In a typical web surfing scenario, a visitor visits a website and use the functionality provided
by that particular website.HTTP request is send to server from web browsers and server
responses are translated by browser to display the desired result of the visitor. But, this
scenario has been changed in the recent days. You don’t need to visit the particular website to
use their service and functionality if they are providing web services. Web services are set of
platform independent exposed APIs(functions) which can be used used from remote server
over the Internet. There are basically two parties involved in this, one which provides a set of
exposed APIs and the another one ,commonly know as web services consumers,is the party
which uses the functionality and services provided by web services providing party.
There are different method for providing web services but the most common are SOAP,
XML-RPC and REST .
SOAP
SOAP was the acronym of Simple Object Access Protocal but this acronym was dropped in
the version of 1.2 of SOAP. It is method for exchanging XML based message over the
Internet for providing and consuming web services. SOAP message are transferred forming
the SOAP-Envelope.You can view the typical SOAP Message articture from here. SOAP is
widely criticized for it’s design complexity.
In PHP 5, there is built-in extension for the providing and consuming web services. But, I
personally prefer Nusoap toolkit of PHP for providing and consuming web services using
SOAP in PHP.
XML-RPC
XML-RPC (remote procedure call) another way of providing and consuming web services. It
uses XML to encode and decode the remote procedure call along with it’s parameter.
Compared to the articture of SOAP, it has simpler architecture. You can even define data type
of parameters of procedure in XML-RPC. You can visit the official website www.xmlrpc.com
to know more about XML-RPC.
In PHP, there is extension which contain various functions for facilating XML-RPC request
and response. But the functions xmlrpc_encode_request() and xmlrpc_decode_request()
available in PHP is very useful for when it comes to encode and decode XML-RPC request
and response.
I’ve built Nepali Currency Converter using XML-RPC web services provided by foxrate.org.
REST
Resources are application’s state and functionality which is represented by a unique URL.
The resources share a uniform interface to transfer the state between the client and server.
Talking about PHP, the format of information(representation) returned can be in XML, JSON
or even in HTML format. DOM functions, SimpleXML functions and JSON functions comes
handy when you are handling RESTful interfaces in PHP.
Travel Agent:
Consider people currently use their browsers to book flights, hotels and care hire with a selection of
different web sites. If each of these web sites were to provide a standard web service interface, then
Travel Agent Service could use their operations in order to provide a traveller with a combination of
these services.
WSDL
WSDL (Web Services Description Language) is an XML-based language for describing Web services
and how to access them.
Before you continue you should have a basic understanding of the following:
XML
XML Namespaces
XML Schema
If you want to study these subjects first, find the tutorials on our Home page.
What is WSDL?
WSDL is a document written in XML. The document describes a Web service. It specifies the
location of the service and the operations (or methods) the service exposes.
Element Defines
<definitions>
<types>
definition of types........
</types>
<message>
definition of a message....
</message>
<portType>
definition of a port.......
</portType>
<binding>
definition of a binding....
</binding>
</definitions>
A WSDL document can also contain other elements, like extension elements, and a service
element that makes it possible to group together the definitions of several web services in one
single WSDL document.
WSDL Ports
It describes a web service, the operations that can be performed, and the messages that are
involved.
The <portType> element can be compared to a function library (or a module, or a class) in a
traditional programming language.
WSDL Messages
Each message can consist of one or more parts. The parts can be compared to the parameters
of a function call in a traditional programming language.
WSDL Types
The <types> element defines the data types that are used by the web service.
For maximum platform neutrality, WSDL uses XML Schema syntax to define data types.
WSDL Bindings
The <binding> element defines the message format and protocol details for each port.
WSDL Example
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
In this example the <portType> element defines "glossaryTerms" as the name of a port, and
"getTerm" as the name of an operation.
The "getTerm" operation has an input message called "getTermRequest" and an output
message called "getTermResponse".
The <message> elements define the parts of each message and the associated data types.
A WSDL port describes the interfaces (legal operations) exposed by a web service.
WSDL Ports
It defines a web service, the operations that can be performed, and the messages that are
involved.
The port defines the connection point to a web service. It can be compared to a function
library (or a module, or a class) in a traditional programming language. Each operation can be
compared to a function in a traditional programming language.
Operation Types
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
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 >
In the example above, the port "glossaryTerms" defines a one-way operation called
"setTerm".
The "setTerm" operation allows input of new glossary terms messages using a
"newTermValues" message with the input parameters "term" and "value". However, no output
is defined for the operation.
Request-Response Operation
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
In the example above, the port "glossaryTerms" defines a request-response operation called
"getTerm".
WSDL bindings defines the message format and protocol details for a web service.
Binding to SOAP
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
The name attribute (you can use any name you want) defines the name of the binding, and the
type attribute points to the port for the binding, in this case the "glossaryTerms" port.
The style attribute can be "rpc" or "document". In this case we use document. The transport
attribute defines the SOAP protocol to use. In this case we use HTTP.
The operation element defines each operation that the port exposes.
For each operation the corresponding SOAP action has to be defined. You must also specify
how the input and output are encoded. In this case we use "literal".
WSDL and UDDI
What is UDDI
UDDI uses World Wide Web Consortium (W3C) and Internet Engineering Task Force (IETF)
Internet standards such as XML, HTTP, and DNS protocols.
Additionally, cross platform programming features are addressed by adopting SOAP, known
as XML Protocol messaging specifications found at the W3C Web site.
UDDI Benefits
Before UDDI, there was no Internet standard for businesses to reach their customers and
partners with information about their products and services. Nor was there a method of how to
integrate into each other's systems and processes.
Making it possible to discover the right business from the millions currently online
Defining how to enable commerce once the preferred business is discovered
Reaching new customers and increasing access to current customers
Expanding offerings and extending market reach
Solving customer-driven need to remove barriers to allow for rapid participation in the global
Internet economy
Describing services and business processes programmatically in a single, open, and secure
environment
How can UDDI be Used
If the industry published an UDDI standard for flight rate checking and reservation, airlines
could register their services into an UDDI directory. Travel agencies could then search the
UDDI directory to find the airline's reservation interface. When the interface is found, the
travel agency can communicate with the service immediately because it uses a well-defined
reservation interface.
UDDI is a cross-industry effort driven by all major platform and software providers like Dell,
Fujitsu, HP, Hitachi, IBM, Intel, Microsoft, Oracle, SAP, and Sun, as well as a large
community of marketplace operators, and e-business leaders.