Tài liệu What Is a Web Service? - Pdf 87



What Is a Web Service?
A Web service is a business component that provides some useful facility to clients, or
consumers. Just as Distributed Component Object Model (DCOM) is thought of as
“COM with a longer wire,” a Web service can be thought of as a component with a truly
global reach. Web services use a standard, accepted, and well-understood protocol called
HTTP to transmit data, and a portable data format that is based on XML. HTTP and
XML are both standardized technologies that can be used by other programming
environments outside of the .NET Framework. So, you can build Web services by using
Visual Studio 2005, and client applications (called consumers) that are running in a
totally different environment, such as Java, can use them. The reverse is also true; you
can build Web services by using Java, and write consumer applications in C#.
You can use several different languages with Visual Studio 2005 to build Web services.
Currently, Microsoft Visual C++, Microsoft Visual C#, Microsoft Visual J#, and
Microsoft Visual Basic .NET are supported, and it is likely that there will be others in the
future. As far as the consumer is concerned, however, the language used by the Web
service, and even how the Web service performs its tasks, is not important. The
consumer's view of a Web service is of an interface that exposes a number of well-
defined methods. All the consumer needs to do is call these methods by using the
standard Internet protocols, passing parameters in an XML format and receiving
responses also in an XML format.
One of the driving forces behind the .NET Framework and future releases of Windows is
the concept of the “programmable Web.” The idea is that, in the future, systems will be
constructed by using the data and services provided by multiple Web services. Web
services provide the basic elements for systems, the Web provides the means to gain
access to them, and developers glue them together in meaningful ways. Web services are
a key integration technology for combining disparate systems together; they are the basis
for many business-to-business (B2B) and business-to-consumer (B2C) applications.
The Role of SOAP
Simple Object Access Protocol (SOAP) is the protocol used by consumers for sending

Content-Length: 579

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://
www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-
envelope">
<soap12:Body>
<HowMuchWillItCost
xmlns="http://www.contentmaster.com/NorthwindServices">
<productName>Chai</productName>
<howMany>39</howMany>
</HowMuchWillItCost>
</soap12:Body>
</soap12:Envelope>
The request contains two parts: a header comprising everything up to the <soap12:Body>
tag, and the actual body of the message in the <soap12:Body> tag. You can see how the
body encodes parameters—in this example, the name of the product is Chai and the
quantity is 39.
The Web server will receive this request, identify the Web service and method to run, run
the method, obtain the results, and send them back to the client as a SOAP result, like
this:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 546

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://
www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-

name="productName" type="s:string" />
<s:element minOccurs="1" maxOccurs="1"
name="howMany" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="HowMuchWillItCostResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1"
name="HowMuchWillItCostResult" type="s:decimal" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>

</wsdl:definitions>
This is known as the Web Service Description (a large chunk has been omitted to save
space), and the schema used is called Web Services Description Language (WSDL). This
description provides enough information to allow a client to construct a SOAP request in
a format that the Web server should understand. The description looks complicated but,
fortunately, Microsoft Visual Studio 2005 contains tools that can parse the WSDL for a
Web service in a mechanical manner, and then use it to create a proxy object that a client
can use to convert method calls into SOAP requests. You will do this later in this chapter.
For now, you can concentrate on building a Web service.
Web Services Enhancements
Not long after Web services became a mainstream technology for integrating distributed
services together, it became apparent that there were issues that SOAP and HTTP alone
could not address. These issues include:

service can negotiate which level of service to use based on the requirements and
cost. However, this negotiation requires that the client and the Web service have a
common understanding of the policies available. The WS-Policy specification
provides a general purpose model and corresponding syntax to describe and
communicate the policies of a Web service.

Routing and addressing. It is useful for a Web server to be able to re-route a Web
service request to one of a number of servers. For example, many scalable systems
make use of load-balancing; requests sent to a server are actually redirected by
that server to other computers to spread the load across those computers. The
server can use any number of algorithms to try and balance the load. The
important point is that this redirection is transparent to the client making the Web


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status