WEB Service教程

來源:互聯網
上載者:User

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)
    簡易物件存取通訊協定 (SOAP)
  • 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)
  • 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 SystemImports System.Web.ServicesPublic Class TempConvert :Inherits WebService<WebMethod()> Public Function FahrenheitToCelsius(ByVal Fahrenheit As Int16) As Int16Dim celsius As Int16 celsius = ((((Fahrenheit) - 32) / 9) * 5) Return celsiusEnd Function<WebMethod()> Public Function CelsiusToFahrenheit(ByVal Celsius As Int16) As Int16Dim fahrenheit As Int16fahrenheit = ((((Celsius) * 9) / 5) + 32) Return fahrenheitEnd FunctionEnd 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 SystemImports 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 Int16Dim celsius As Int16 celsius = ((((Fahrenheit) - 32) / 9) * 5) Return celsiusEnd Function<WebMethod()> Public Function CelsiusToFahrenheit(ByVal Celsius As Int16) As Int16Dim fahrenheit As Int16fahrenheit = ((((Celsius) * 9) / 5) + 32) Return fahrenheitEnd Function

The last thing to do is to end the function and the class:
最後一步是結束函數和類:

End FunctionEnd 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,你可以把我們的網頁服務放在你的位置上。就像這樣:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.