Web Services 简介
In this column we embark on a new series on Web services. Web services are expected to revolutionize our life in much the same way as the Internet has during the past decade or so. Web services provide a common protocol that Web applications can use to connect to each other over the Internet. The main advantage of Web services is that they are based on industry standards. The services are described in XML and are communicated over the existing HTTP infrastructure. The union of XML and HTTP forms one of the new industry buzz words: Simple Object Access Protocol (SOAP). Publicizing Web services is done via two standards: Universal Description, Discovery, and Integration (UDDI), and DISCO (abbreviation of Discovery). The big computer companies are betting on this new technology. They are developing platforms, tools, and kits to help build Web services.
2,Motivation behind Web Services
Bill Gates, in his leaflet to Developers & IT Professionals from June 14, 2001, covers the motivation for Web services, and the XML's role in this technology. We point out some of his arguments in this column.
Revolutions are a way of life in the computer industry. Only 20 years ago, the world was still in the mainframe era. Few people had access or used computers, and when they did, it was only through the nearest computer center. Three innovations changed all that: the PC, the GUI, and the Internet. Since then, standards such as HTML and HTTP have exponentially increased people's use of the Internet. This base protocol for viewing content on the Web (and the associated software for browsing this content) grew Web usage to what you are familiar with today. The Web became a key activity in the daily lives of businesses, employees, and consumers.
"Many of us envision an online world where constellations of PCs, servers, smart devices, and Internet-based services can collaborate seamlessly. Businesses will be able to share data, integrate their processes, and join forces to offer customized , comprehensive solutions to their customers. The information you or your business need will be available wherever you are, and whatever computing device, platform, or application you are using."
"That vision has yet to be achieved. In many respects, today's Internet still mirrors the old mainframe world. It's a server-centric computing model, with the browser playing the role of dumb terminal. Much of the information you or your business needs is locked up in centralized databases, served up a page at a time to individual users. Web pages are simply a "picture" of the data, not the data itself, forcing many developers back to "screen scraping" to acquire information. Integrating that underlying data with your business's existing systems is a costly and frustrating challenge."
"Today's standalone applications and Web sites create islands of functionality and data. You have to navigate manually between Web sites, devices, and applications, logging in each time, and rarely being able to carry data with you. Tasks that ought to be simple, such as arranging a meeting with colleagues from partner companies and automatically updating every attendee's calendar, are a nightmare in the best case, and impossible in the common case. This inefficiency is a major source for productivity loss."
As a result of the changes in how businesses and consumers use the Web, the industry is converging on a new computing model that enables a standard way of building applications and processes to connect and exchange information over the Web. This new Internet-based integration methodology, called "XML Web services," enables applications, machines, and business processes to work together in a revolutionary way. The widespread support around XML assures that businesses will cooperate in the Internet-based economy with this XML Web services model.
"At the heart of the solution is XML (eXtensible Markup Language). XML is an open industry standard managed by the World Wide Web Consortium. It enables developers to describe data being exchanged between PCs, smart devices, applications, and Web sites. Since the data is separate from the format and style definitions, it can be easily organized, programmed, edited, and exchanged between any Web sites, applications, and devices. Just as the Web revolutionized how users talk to applications, XML transforms how applications talk to each other."
Microsoft would like to convince us that Web services is the next revolution after the Web and HTTP. Judging from the Sun-Microsoft war on which Web services environment is better, Microsoft may be able to prove it.
3,Benefits of Web Services
Experts and visionaries believe that the benefits of XML Web services will be instrumental in propelling explosive business growth over the next few years. One of the major benefits is Web services' ease of integration. You will easily integrate your software with other pieces of software. You can run on all kinds of machines, from the desktop to the mainframe, either within your enterprise or at external sites. This ease of integration will enable tighter business relationships and more efficient business processes.
With Web services readily available, and as the pool of XML Web services grows, you will be able to find software modules that can be integrated into your own application, by finding it and integrating it through XML Web services. Integrate with existing Web services instead of reinventing them. The bottom line is that you will be able to develop applications much faster than before.
An integral part of the XML Web services programming model, is the ease of integration with external data sources. No longer does each application need to copy and maintain external data sources. You can request and get information in real time, and transform it to your particular format. This will allow you to deliver individualized software and services, while your maintenance burden is reduced.
Consumers will enjoy ease of use when using XML Web services-based applications. XML Web services link applications, services, and devices together. Using Web services will be an integrated experience that excels in its simplicity. XML Web services give users the ability to act on information any time, any place, and from any smart device.
Businesses will love Web services because it will force them to streamline their processes. All suppliers will use the same language to describe their offerings. An XML Web service is a simple, reliable way to blend existing systems with new applications and services.
Microsoft is already sporting several commercial applications that were written in a record speed, thanks to the use of XML Web services. The first one is from Dollar Rent-A-Car. In two weeks, programmers built, tested, and deployed a Web Services-based solution that translates reservation requests and data between the company's mainframe-based reservation system and an airline partner's UNIX servers. Dollar can now reuse the same integration model to link their reservation system with other airline or hotel partners. The second case is expedia.com. This is a site that will find you the lowest price itinerary. They are now in the process of transforming itineraries into communication centers. These centers are Web services that users can access to get relevant and timely information at their convenience. With this new service, Expedia hopes to attract new customers and further strengthen the loyalty of their existing customer base.
4,SOAP and UDDI
You call Web services with messages that are written in the SOAP format. SOAP is a specification that defines the XML format for messages. A well-formed XML fragment enclosed in a couple of SOAP elements is a SOAP message. SOAP stands for Simple Object Access Protocol. You could print out a SOAP message, fax it to a remote location, and type it into the remote machine without violating the SOAP standard. More likely, you would send a SOAP message inside an HTTP message. There's no standard for how a SOAP message is carried, and SOAP doesn't care what the transport is. The SOAP specification defines what an HTTP message containing a SOAP message must look like.
The SOAP specification includes three major parts. The required part defines the structure of an XML document that can be used to exchange data between applications. Section 5 defines a way to encode programming language data types in XML. Such a message is called a section-5 encoded SOAP message. A regular message that contains an XML document is called a literal SOAP message. Section 7 of the SOAP definition is also optional. It deals with RPC (remote procedure calls), where the message is sent synchronously. You call a Web service's function and wait to check the return code. The default specification is for asynchronous call.
One of the critical principles of XML Web services is that systems connect through the Internet, which is a safe assumption. Internet connectivity is readily available and is provided with a very low cost to users of these Web services. The only problem is how to find these resources on the Internet. Will there be search engines? Directories? Some of the big computer companies such as Microsoft, Ariba, COMPAQ, Dell, HP, IBM, SAP, and others, are participating in a broad industry effort to define UDDI (Universal Description, Discovery, and Integration). UDDI provides a way to locate and understand services provided by other companies. It's a kind of "yellow pages" on the Internet for the industry.
With the momentum behind XML Web services growing among developers, computer companies are building platforms to help them write, deploy, use, and manage these services. Sun is promoting its Sun Open Net Environment (Sun ONE) for these purposes. Microsoft has its own platform, the .NET (pronounced dotnet) platform. It contains both products and services developers need to build and run XML Web services. It also enables integration of XML Web services with other computers, smart devices, and other Web-based services. Because XML is an open standard, Microsft assures us that the products and services within Microsft .NET will interoperate with a broad set of XML- and XML Web services-enabled infrastructure and developer tools from other vendors.
Under the umbrella of the .NET environment, Microsoft is promoting two major tools: Visual Studio.NET and .NET Framework. Visual Studio.NET is Microsoft's next generation multi-language development tool. It helps developers quickly build XML Web services and applications that scale easily, using the language of their choice. The supported languages are: Visual Basic, which includes new object-oriented programming features, Visual C++, which advances Windows-based development and enables you to build .NET applications, and C#, which brings RAD (Rapid Application Development) to C and C++ developers. Other languages will be supported by third parties: Perl, Python, COBOL, and Eiffel.
The .NET Framework is a high-productivity, standards-based, multi-language application execution environment that handles essential plumbing chores and eases deployment. The .NET Framework improves the reliability, scalability, and security of your application. It includes several parts: the Common Language Runtime, a rich set of class libraries for building XML Web services, and ASP.NET, the next generation Active Server Pages.
When planning to use a new Web service, you need to learn its interface first. You can learn it from the Web service's WSDL (Web Services Description Language) document. It describes the messages that the Web service understands, the format of its responses to those messages, the protocols that the service support, and so on. The WSDL document is easy to browse. Just click the lines beginning with the ("-") and plus ("+") signs, to contract or expand the code.The WSDL document can be divided into two groups: the Abstract Definitions Group and the Concrete Descriptions Group. The abstract sections define SOAP messages in a platform- and language-independent manner; they don't contain any machine- or language-specific elements. The concrete sections are site-specific, machine-specific, or language-specific. The abstract elements are types, message, and portType. The concrete elements are binding and service.
The root of any service description file is the <definitions> element. The <definitions> elements includes the namespace definitions. In the Weather - Temperature Web service, it looks like this:
The types element contains datatype definitions. Usually, this element includes a schema element that defines various datatypes. Here is a complexType element definition from the interopTest Web service's types element:
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://soapinterop.org/xsd">
<element name="item" type="string" maxOccurs="unbounded" />
<attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="string" />
The message element describes the data being exchanged between the Web service providers and consumers. Each Web method has two messages: input and output. The input describes the parameters for the Web method; the output describes the return data from the Web method. Each message contains zero or more <part> parameters, one for each parameter of the Web method. Each parameter associates with a concrete type defined in the <types> container element. In the Temperature - Weather Web service, the input parameter is a string-typed zip code. Here is how the <message> element is defined:
<part name="zipcode" type="xsd:string"/>
The portType element includes a supported set of operations. Each operation includes the input and the output messages of the operation. Here is the getTemp operation from the Temperature - Weather Web service:
<input message="tns:getTempRequest" />
<output message="tns:getTempResponse" />
Each binding element describes a supported protocol. Similar to the portType element, the binding element includes supported operations, as well as the input and output for each operation. Here is the binding element from the Temperature - Weather Web service:
<binding name="TemperatureBinding" type="tns:TemperaturePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<soap:operation soapAction="" />
<soap:body use="encoded" namespace="urn:xmethods-Temperature"
<soap:body use="encoded" namespace="urn:xmethods-Temperature"
The service element is a collection of ports. Each port supports a different protocol. Here is a SOAP port from the Temperature -- Weather Web service:
<documentation>Returns current temperature in a given U.S. zipcode</documentation>
<port name="TemperaturePort" binding="tns:TemperatureBinding">
<soap:address location="http://services.xmethods.net:80/soap/servlet/rpcrouter" />
7,A Final Word
In this column we embarked on a new series on Web services. We introduced you to the concept, the motivation behind them, and the benefits you are expected to get from them. We explained several basic terms, such as SOAP, XML, UDDI, and WSDL. We pointed out to you two directories where you can find hundreds of readily-available Web services. Using a Web service necessitates a careful screening of candidates. One criterion to judge by is the Web service's quality, and adherence to its specification. Luckily, there are Web sites that check the interoperability between Web services. We showed you a way to check if the recent regression suite passed or failed. The Web Service Description Language (WSDL) is used to describe the service's interface. We listed the description file of a Web service that returns the weather in a given zip-code area. We went over the WSDL's abstract and concrete definitions.