WEB Service教程[转]

WEB Server教程

网络服务可以使你的应用程序称为网络应用程序
通过使用网络服务,你的应用程序可以向世界的各个角落发布它的函数或信息。

网络服务可以被其它应用程序使用。
通过网络服务,你可以将公司会计部门的Win2000服务器与技术提供部门的UNIX服务器相连接。

基本网络服务平台是XML + HTTP。
网络服务使用XML对你的数据进行编码或解码;使用SOAP传输这些数据。

学习如何通过ASP.NET应用程序创建一个网络服务
该教程将ASP.NET转换为一个网络服务。

内容列表

网络服务介绍 - 介绍什么是网络服务

为什么使用网络服务? - 介绍使用网络服务的方法和原因。

网络服务平台 - 介绍网络平台包含的具体元素。

网络服务案例 - 以一个ASP.NET为案例的网络服务。

网络服务用法 - 介绍如何将你的网络服务放到网站上。

网络服务概述 - 对本章所学的知识进行总结,并推荐你下一步该学的知识。

WS 介绍
w3pop.com / 2006-09-21

使用WS的原因

Web Services can make your applications Web applications.
网络服务可以使你的应用程序称为网络应用程序

Web Services are published, found and used through the Web.
网络服务是通过网页公布,寻找和使用的。


What You Should Already Know
学前基础

Before you continue you should have a basic understanding of the following:
在继续之前你该对以下概念有基本了解:

  • HTML
  • XML

If you want to study these subjects first, find the tutorials on our Home page.
如果你想先学这些内容,请看我们Home page.的教程


What are Web Services?
什么是网络服务?

  • Web services are application components
    网络服务是应用程序的组件。
  • Web services communicate using open protocols
    网络服务的通信用到开放式协议
  • Web services are self-contained and self-describing
    网络服务是自我包含和自我描述的。
  • Web services can be discovered using UDDI
    网络服务可以通过UDDI被发现
  • Web services can be used by other applications
    网络服务可被其他应用软件使用。
  • XML is the basis for Web services
    XML是网络服务的基本要素。

How Does it Work?
它怎样工作的?

The basic Web services platform is XML + HTTP.
基础网络服务平台是XML + HTTP.

The HTTP protocol is the most used Internet protocol.
HTTP协议是最常用的英特网协议

XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions.
XML 语言能在不同平台和程序设计语言之中被使用,并且仍可以表达复杂的信息和函数。

Web services platform elements
网络服务平台元素

  • SOAP (Simple Object Access Protocol)
    简单对象访问协议
  • UDDI (Universal Description, Discovery and Integration)
    通用描述,发现和综合
  • WSDL (Web Services Description Language)
    网络描述语言

We will explain these topics later in the tutorial
在下面的教程里我们会解释这些内容


The Future of Web services
网络服务的前景

Don't expect too much, too soon.
不要期待得太多,太急。

The Web Services platform is a simple, interoperable, messaging framework. It still misses many important features like security and routing. But, these pieces will come once SOAP becomes more advanced.
网络服务平台是简单的,能共同操作的,通信框架。它仍缺少许多重要的特征如安全和路由。可是一旦SOAP能变得更高级一些,这些特征也就会有了。

Hopefully, Web services can make it much easier for applications to communicate. 
当然很有希望的 ,网络服务能使应用程序更方便的通信。

使用WS的原因
w3pop.com / 2006-09-21

WS 介绍 WS 平台

A few years ago Web services were not fast enough to be interesting.
几年前,网络服务并不能快速地引起别人的关注。

Thanks to the major IT development the last few years, most people and companies have broadband connection and use the web more and more.
要感谢这几年IT的快速发展,大多数人和公司都有宽带连接,并越来越多地用到了网络。


Interoperability has highest priority.
互用性有最高的优先权

When all major platforms could access the Web using Web browsers, different platforms could interact. For these platforms to work together, Web applications were developed.
当所有重要的平台可以通过使用网页浏览器来访问网络,不同平台会互相作用和影响。为了使这些平台能协同工作,网络应用软件应运而生。

Web applications are simple applications run on the web. These are built around the Web browser standards and can mostly be used by any browser on any platform.
网络应用软件是运行在网络上的简单的应用程序。这些都是根据网络浏览器标准而建立的,并且几乎能在任何平台任何浏览器上被使用。


Web services take Web applications to the next level.
网络服务使网络应用程序步入下一阶段

Using Web services your application can publish its function or message to the rest of the world.
利用网络服务你的应用软件可以向全世界公布它的函数或信息

Web services uses XML to code and decode your data and SOAP to transport it using open protocols.
网络服务用XML对你的数据进行编码和解码,并使用开放式协议SOAP传送数据

With Web services your accounting departments Win 2k servers billing system can connect with your IT suppliers UNIX server.
用上网络服务,你的会计部门(accounting departments)Win 2k系统服务器可以和你的IT提供商UNIX服务器连接


Web services have two types of uses.
网络服务有两种类型用途

Reusable application components
可再度利用的应用程序组件

There are things different applications needs 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.
网络服务可以提供像货币兑换、天气预报、语言翻译这样的应用程序组件作为服务内容。

Ideally, there will only be one type of each application component, and anyone can use it in their application.
理想化来说,将来只会有一种类型的应用程序组件,每个人都可在他们的应用程序里使用它。

Connect existing software
连接现有软件

Web services help solve the interoperability problem by giving different applications a way to link their data.
网络服务可以通过给不同的应用软件一种方式连接数据,来解决互用性问题

Using Web services you can exchange data between different applications and different platforms.
使用网络服务你可以在不同的应用软件和不同平台之间交换数据。

WS 平台
w3pop.com / 2006-09-21

使用WS的原因 WS 实例

Web Services have three basic platform elements.
网络服务平台元素

These are called SOAP, WSDL and UDDI.
网络服务有三个基本平台元素,成为SOAP, WSDL 和UDDI.


What is SOAP?
什么是SOAP?

The basic Web services platform is XML plus HTTP.
基础网络服务平台是XML plus HTTP

  • SOAP stands for Simple Object Access Protocol
    • SOAP意思是“Simple Object Access Protocol”简单对象访问协议
  • SOAP is a communication protocol
    • SOAP是通信协议
  • SOAP is for communication between applications
    • SOAP用于应用程序间的通信
  • SOAP is a format for sending messages
    SOAP是用于传送信息的格式
  • SOAP is designed to communicate via Internet
    SOAP通过英特网通信
  • SOAP is platform independent
    SOAP是平台独立的
  • SOAP is language independent
    SOAP是语言独立的
  • SOAP is based on XML
    SOAP是以XML为基础的
  • SOAP is simple and extensible
    SOAP是浅易的并可扩展的
  • SOAP allows you to get around firewalls
    SOAP允许你通过防火墙
  • SOAP will be developed as a W3C standard
    SOAP将会成为一个W3C标准

Read more about SOAP on our Home page.
在我们的Home page.上阅读更多关于SOAP


What is WSDL?
什么是WSDL?

WSDL is an XML-based language for describing Web services and how to access them.
WSDL是用于描述网络服务以及怎样访问它们的以XML为基础的语言。

  • WSDL stands for Web Services Description Language
    WSDL意思是Web Services Description Language(网络服务描述语言)
  • WSDL is written in XML
    WSDL是以XML形式写成的
  • WSDL is an XML document
    WSDL是一份XML文档
  • WSDL is used to describe Web services
    WSDL用于描述网络服务
  • WSDL is also used to locate Web services
    WSDL也用于定位网页服务
  • WSDL is not yet a W3C standard
    WSDL是一个W3C标准

Read more about WSDL on our Home page.
在我们Home page.上阅读更多有关WSDL


What is UDDI?
什么是UDDI?

UDDI is a directory service where businesses can register and search for Web services.
UDDI是商家可以用来登记和搜索网络服务的目录服务

  • UDDI stands for Universal Description, Discovery and Integration
    Integration UDDI意思是“Universal Description, Discovery and Integration”(通用描述,发现和综合)
  • UDDI is a directory for storing information about web services
    • UDDI是储存关于网络服务信息的目录
  • UDDI is a directory of web service interfaces described by WSDL
    • UDDI是以WSDL描述的网络服务界面的目录。
  • UDDI communicates via SOAP
    UDDI通过SOAP协议通信
  • UDDI is built into the Microsoft .NET platform
    UDDI建在Microsoft .NET平台之中。

Read more about UDDI on our Home page.
在Home page中阅读更多关于. UDDI

WS 实例
w3pop.com / 2006-09-21

WS 平台 WS 的使用

Any application can have a Web Service component.
任何应用程序都可以有一个网络服务组件

Web Services can be created regardless of programming language.
网络服务的创建可以不用考虑设计语言


An example ASP.NET Web Service
ASP.NET网络服务示例

In this example we use ASP.NET to create a simple Web Service.
在这个例子里我们用ASP.NET创建一个简单的网络服务

<%@ WebService Language="VB" Class="TempConvert" %>

Imports System
Imports System.Web.Services


Public Class TempConvert :Inherits WebService

<WebMethod()> Public Function FahrenheitToCelsius
(ByVal Fahrenheit As Int16) As Int16
	Dim celsius As Int16 
	celsius = ((((Fahrenheit) - 32) / 9) * 5) 
	Return celsius
End Function

<WebMethod()> Public Function CelsiusToFahrenheit
(ByVal Celsius As Int16) As Int16
	Dim fahrenheit As Int16
	fahrenheit = ((((Celsius) * 9) / 5) + 32) 
	Return fahrenheit
End Function
End Class

This document is a .asmx file. This is the ASP.NET file extension for XML Web Services.
这份文档是份a .asmx文件。这是XML网页服务的ASP.NET文件扩展名。


To run this example you will need a .NET server.
要运行这个例子你需要一个a .NET服务器

The first line in this document that it is a Web Service, written in VB and the class name is "TempConvert":
文档的首行声明了文档是一个以VB编写,类名为"TempConvert"的网络服务:

<%@ WebService Language="VB" Class="TempConvert" %>

The next lines imports the namespace "System.Web.Services" from the .NET framework.
接下来几行从the .NET框架中输出了名称空间"System.Web.Services"

Imports System
Imports System.Web.Services

The next line defines that the "TempConvert" class is a WebSerivce class type:
接下来一行定义了"TempConvert"类是一个网页服务类型。

Public Class TempConvert :Inherits WebService

The next step is basic VB programming. This application has two functions. One to convert from Fahrenheit to Celsius, and one to convert from Celsius to Fahrenheit.
下步是基本的VB编程。这个应用程序有两个函数。一个是把华式摄氏度转换成摄氏度,一个是把摄氏度转换成华式摄氏度。

The only difference from a normal application is that this function is defined as a "WebMethod".
和普通应用软件的唯一不同之处事这个函数定义为一个"WebMethod".(网页方法)

Use "WebMethod" to mark the functions in your application that you would like to make into web services.
用"WebMethod"(网页方法)在你的想做成网页服务的应用程序中标记函数

<WebMethod()> Public Function FahrenheitToCelsius
(ByVal Fahrenheit As Int16) As Int16
	Dim celsius As Int16 
	celsius = ((((Fahrenheit) - 32) / 9) * 5) 
	Return celsius
End Function

<WebMethod()> Public Function CelsiusToFahrenheit
(ByVal Celsius As Int16) As Int16
	Dim fahrenheit As Int16
	fahrenheit = ((((Celsius) * 9) / 5) + 32) 
	Return fahrenheit
End Function

The last thing to do is to end the function and the class:
最后一步是结束函数和类:

End Function

End Class

If you save this as an .asmx file and publishes it on a server with .NET support, you should have your first working Web Service. Like our example Web Service
如果你想把它保存为一份.asmx文件,并发表在有.NET支持的服务器上,那就必须有你的首个工作网络服务系统,类似于我们的example Web Service 。


ASP.NET automates the process
ASP.NET会使过程自动化

With ASP.NET you do not have to write your own WSDL and SOAP documents.
有了ASP.NET,你不必自己编写WSDL 和 SOAP文档。

If you look closer on our example Web Service. You will see that the ASP.NET has automatically created a WSDL and SOAP request.
如果你再仔细地看看我们的示例网络服务,你会看到ASP.NET已经自动生成了WSDL和SOAP请求

WS 的使用
w3pop.com / 2006-09-21

WS 实例 WS 摘要

Using our example ASP.NET Web Service
用我们示例的ASP.NET网页服务

In the previous example we created an example Web Service.
在前个例子里我们创建了一个网页服务的例子example Web Service.

The Fahrenheit to Celsius function can be tested here: FahrenheitToCelsius.
华式摄氏度转换成摄氏度的函数可以在这测试:FahrenheitToCelsius.

The Celsius to Fahrenheit function can be tested here: CelsiusToFahrenheit.
摄氏度转化为华式摄氏度的函数可以在这里测试:CelsiusToFahrenheit.


These functions will send you a XML reply.
这些函数会给你一个XML的回复

These test use HTTP POST and will send a XML response like this:
这些例子使用HTTP POST,并会给出一个像这样的回复:

<?xml version="1.0" encoding="utf-8" ?> 
<short xmlns="http://tempuri.org/">38</short>


Use a form to access a Web Service.
用表格访问网页服务

Using a form and HTTP POST, you can put our web service on your site, like this:
用表格和HTTP POST,你可以把我们的网页服务放在你的位置上。就像这样:

Fahrenheit to Celsius:
 
Celsius to Fahrenheit:
 
<form target="_blank" action='http://www.w3schools.com
/webservices/tempconvert.asmx/FahrenheitToCelsius'
method="POST">
<table>
<tr>
<td>Fahrenheit to Celsius:</td>
<td><input class="frmInput" type="text"
size="30" name="Fahrenheit"></td>
</tr>
<tr>
<td></td>
<td align="right"> <input type="submit"
value="Submit" class="button"></td>
</tr>
</table>
</form>

<form target="_blank" action='http://www.w3schools.com
/webservices/tempconvert.asmx/CelsiusToFahrenheit'
method="POST">
<table>
<tr>
<td>Celsius to Fahrenheit:</td>
<td><input class="frmInput" type="text"
size="30" name="Celsius"></td>
</tr>
<tr>
<td></td>
<td align="right"> <input type="submit"
value="Submit" class="button"></td>
</tr>
</table>
</form>

WS 摘要
w3pop.com / 2006-09-21

WS 的使用

Web Services Summary
网络服务摘要

This tutorial has taught you how to convert your applications into web-applications.
这篇教程教了你怎样把应用程序转换成为网络应用程序。

You have learned how to use XML to send messages between applications.
你已经学了怎样用XML在应用程序之间传送信息

You have also learned how to export a function (create a web service) from your application.
你也学了怎样从应用程序中输出函数(创建网页服务)


Now You Know Web Services, What's Next?
现在你知道网络服务,那接着呢?

The next step is to learn about WSDL and SOAP.
下步是学习有关WSDL和 SOAP.

WSDL

WSDL is an XML-based language for describing Web services and how to access them.
WSDL是用于描述网络服务和怎样访问它们的以XML为基础的语言

WSDL describes a web service, along with the message format and protocol details for the web service.
WSDL描述了网络服务,以及网络服务的信息格式和协议细节。

If you want to learn more about WSDL, please visit our WSDL tutorial.
想了解更多关于WSDL,请访问我们的WSDL tutorial.

SOAP

SOAP is a simple XML-based protocol that allows applications to exchange information over HTTP.
SOAP是允许应用程序通过HTTP交换信息的简单的以XML为基础的协议

Or more simply: SOAP is a protocol for accessing a web service.
或者说得更简单些:SOAP是用于访问网络服务的协议

If you want to learn more about SOAP, please visit our SOAP tutorial.
如果想了解更多关于SOAP,请访问我们的SOAP tutorial.

posted @ 2006-11-18 11:01  疯一样的自由  阅读(8827)  评论(0编辑  收藏  举报