|
|
what are web services?
What is a Web Service?
Why use Web Services?
How do Web Services Work?
|
| What is a Web Service?
|
A Web Service is a piece of software that provides a useful function to a customer that
is accessed over the Internet.
The principles behind Web Services are simple:
- The Web Service provider defines a format for requests for its service and the
response the service will generate.
- A customer makes a request for the Web Service across the Internet.
- The Web Service performs some action and sends a response back over the Internet.
The action performed could be anything such as retrieving a stock quote, finding the
best price for a particular product, saving a new meeting to a calendar, validating a
credit card number or in the case of GetData retrieving credit information about a
company.
Many organisations provide Web Services:
- Amazon.com provides a Web Service that allows customers to search its product data,
purchase products and track the status of a transaction.
- Google.com and Yahoo.com provide Web Services that allow customers to search the
Internet for web content.
- Microsoft provides a .NET Passport Web Service that authenticates a .NET username
and password.
|
|
| What use Web Services?
|
The true power of Web Services is that they allow companies to combine existing computer systems
over the Internet within the business and/or across many businesses. Web Service technology
makes it easier for companies to integrate software and reuse software that they or others have
already built.
Web Services open the possibility to a number of functions:
- Application-to-Application Integration
For example, the Stock Management System could
automatically place an order with the Order Management System when stocks reach a certain level.
- Business-to-Business Integration
For example, Company A's Stock Management System could
automatically order stock from Company B's Order System when stocks reach a certain level.
- Information Distribution
For example, a Company could expose its price-list that allows
customers to view, search or integrate this information with their systems.
- Application Functionality
For example, a standard encryption function could be exposed
that allows any application to use this function over the Internet.
The main advantage of Web Services is that they are based on two well understood,
industry standard technologies: the Internet and XML. Most businesses already
have an Internet infrastructure and people with the knowledge and experience to
maintain it. XML is used to format the request and response messages sent between
a customer and a Web Service. XML provides a method to mask the differences between
disparate software systems thus any system that understands XML can call a Web
Service.
|
|
| How do Web Services Work?
|
|
A Web Service exposes a number of well-defined methods that a customer can call. These
methods are specified in an XML based language called Web Service Description
Language (WDSL). A WSDL document provides a customer with enough information to
construct a request message in a format the Web Service understands. A WSDL
document also provides a customer with the structure of the response message
received from the Web Service. The WSDL specifies the method name, the input
required and the return value for each method.
For example, consider a Web Service method that takes a firstname and lastname as
input and returns the full name. Figure 1 shows an extract of the WSDL
document for this Web Service method.
<s:schema targetNamespace="http://www.domain.com/services/">
<s:element name="fullname">
<s:complextype>
<s:sequence>
<s:element minOccurs="0"
maxOccurs="0"
name-"firstname"
type="s:string"/>
<s:element minOccurs="0"
maxOccurs="0"
name-"lastname"
type="s:string"/>
</s:sequence>
</s:complextype>
</s:element>
<s:element name="fullnameResponse">
<s:complextype>
<s:sequence>
<s:element minOccurs="0"
maxOccurs="0"
name-"fullnameResult"
type="s:string"/>
</s:element>
</s:sequence>
</s:complextype>
</s:element>
</s:schema>
|
Figure 1: Example WDSL Document
The WSDL Document shows that the method "fullname" requires two string input parameters
"firstname" and "lastname" and returns a string result "fullnameResult".
A customer calling a Web Service method is similar to a customer calling a regular method.
The only difference is that instead of calling a method that is located within the customer
application a request message is generated to the structure specified in the WSDL document.
The request message contains the information that the Web Service needs to process the
request and is sent to the Web Service over the Internet. The Web Service processes the
information and sends the result back, in the structure specified by the WSDL document,
over the Internet, to the customer.
Representational State Transfer (REST) and Simple Object Access Protocol (SOAP) are two
technologies that allow customers to call a Web Service method. REST allows a Web Service
to be referenced by a Uniform Resource Locator (URL). SOAP defines a
structured format for messages sent to and received from a Web Service. The GetData
Web Service supports both REST and SOAP.
REST uses URLs with specific name/value pairs to request information and operates in the
same way as requesting an ordinary Web Page. As REST is based on such a widely accepted
methodology, most developers are able to get started with REST using a moderate amount of
code and without having to learn many new concepts. Figure 4 shows how to call a Web
Service "fullname" method using REST and the GET HTTP command to invoke the
Web Service passing the input parameters in the URL.
|
http://www.domain.com/services.asmx/fullname?firstname=Bart&lastname=Simpson
|
Figure 2: REST GET Request
Figure 3 uses the POST HTTP command to invoke the Web Service. The parameters are
passed in the HTTP header. The advantage of using POST over GET is that the
data is not visible in the URL.
http://www.domain.com/services.asmx/fullname
firstname=Bart&lastname=Simpson
|
Figure 3: REST POST Request
When a Web Service is invoked using REST the results of the Web Service are returned
in an XML response message. An example XML response message is shown in figure 4.
|
<string xmlns="http://www.domain.com/services/">Bart Simpson</string>
|
Figure 4: REST Response
SOAP uses XML to define a message structure that can be exchanged over the Internet.
Customers can create the underlying SOAP data structures themselves but often a
toolkit is used specific to their programming language and operating system.
These toolkits simplify the process of making SOAP calls and processing the
returned results. Figure 5 shows how a Web Service can be called using
SOAP.
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3/org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"></string>
<soap:Body>
<fullname xmlns="http://www.domain.com/services/">
<firstname>Bart</firstname>
<lastname>Simpson</lastname>
</fullname>
</soap:Body>
</soap:Envelope>
|
Figure 5: SOAP Request (using REST)
A SOAP response message is returned by a Web Service call
made by a SOAP request as shown in figure 6.
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3/org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"></string>
<soap:Body>
<fullnameResponse xmlns="http://www.domain.com/services/">
<fullnameResult>Bart Simpson</fullnameResult>
</fullnameResponse>
</soap:Body>
</soap:Envelope>
|
Figure 6: SOAP Response (using REST)
|
|
|
|
|
|