Web Services 教程——Web Services 实例
来源:互联网 发布:淘宝房产网 编辑:程序博客网 时间:2024/05/17 01:10
本章原文地址:http://www.w3schools.com/webservices/ws_example.asp
Web Services Example
Web Services例子
Any application can have a Web Service component.
任何应用程序都可以有一个Web Service组件。
Web Services can be created regardless of programming language.
Web Services的创建与编程语言无关。
---------------------------------------------------------------------
A Web Service Example
一个Web Services例子
In the following example we will use ASP.NET to create a simple Web Service that converts the temperature from Fahrenheit to Celsius, and vice versa:
在以下的例子中我们将使用ASP.NET来创建一个简单的Web Services,它用来实现华氏温度与摄氏温度的相互转化。
<%@ WebService Language="VBScript" Class="TempConvert" %>
Imports System
Imports System.Web.Services
Public Class TempConvert : Inherits WebService
<WebMethod()> Public Function FahrenheitToCelsius(ByVal Fahrenheit As String) As String
Dim fahr
fahr = Trim(Replace(Fahrenheit, ",", "."))
If fahr = "" Or IsNumeric(fahr) = False Then Return "Error"
Return ((((fahr) - 32) / 9) * 5)
End Function
<WebMethod()> Public Function CelsiusToFahrenheit(ByVal Celsius As String) As String
Dim cel
cel = Trim(Replace(Celsius, ",", "."))
If cel = "" Or IsNumeric(cel) = False Then Return "Error"
Return ((((cel) * 9) / 5) + 32)
End Function
End Class
This document is saved as an .asmx file. This is the ASP.NET file extension for XML Web Services.
另存这份文档为一个.asmx文件,这是ASP.NET中XML Web Services类型文件的扩展名。
---------------------------------------------------------------------
Example Explained
例子解释
Note: To run this example, you will need a .NET server.
注:要运行这个例子,您需要一个.NET服务器。
The first line in the example states that this is a Web Service, written in VBScript, and has the class name "TempConvert":
例子的第一行声明这是一个Web Services,使用VBScript编写,并且它的类名是“TempConvert”:
<%@ WebService Language="VBScript" Class="TempConvert" %>
The next lines import the namespace "System.Web.Services" from the .NET framework:
下两行从.NET框架中导入命名空间“System.Web.Services”:
Imports System
Imports System.Web.Services
Public Class TempConvert : Inherits WebService
The next line defines that the "TempConvert" class is a WebService class type:
下一行定义了“TempConvert”类是一个WebService类的类型(注:TempConvert类继承了WebService类):
The next steps are 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 convert the functions in your application into web services:
使用“WebMethod()”将您应用程序中的函数转化为Web Services:
<WebMethod()> Public Function FahrenheitToCelsius(ByVal Fahrenheit As String) As String
Dim fahr
fahr = Trim(Replace(Fahrenheit, ",", "."))
If fahr = "" Or IsNumeric(fahr) = False Then Return "Error"
Return ((((fahr) - 32) / 9) * 5)
End Function
<WebMethod()> Public Function CelsiusToFahrenheit(ByVal Celsius As String) As String
Dim cel
cel = Trim(Replace(Celsius, ",", "."))
If cel = "" Or IsNumeric(cel) = False Then Return "Error"
Return ((((cel) * 9) / 5) + 32)
End Function
End Class
Then, end the class:
然后,结束这个类:
Publish the .asmx file on a server with .NET support, and you will have your first working Web Service.
在使用.NET支持的服务器上发布这个.asmx文件,您将第一次在Web Services上工作。
Look at our example Web Service
观看我们的Web Service实例
(注:http://www.w3schools.com/webservices/tempconvert.asmx)
---------------------------------------------------------------------
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 at our example Web Service, you will see that ASP.NET has automatically created a WSDL and SOAP request.
如果您仔细观看了Web Service实例,你将发现ASP.NET自动地创建了一个WSDL和SOAP请求。
- Web Services 教程——Web Services 实例
- Web Services 教程——Web Services 简介
- Web Services 教程——为何要使用Web Services?
- Web Services 教程——Web Services 平台元素
- Web Services教程——目录
- Web Services 教程——前言
- Web Services使用实例
- web Services入门实例
- web services教程
- Web Services 教程
- Web Services 教程
- Web Services教程
- w3school Web Services 教程
- Web Services 系列教程
- Web Services 教程——Web Services总结及今后学习建议
- axis2开发web services实例
- Web Services
- Web Services
- oracle的表分析(1)
- 在研究百度手写功能时遇到Unexpected end of file from server错误,为什么?
- Xftp可以使用SSH协议进行传输
- RTP报文格式、各种参数意义、编码速率计算
- 关于Linux使用的真实内存
- Web Services 教程——Web Services 实例
- 黑马程序员Java培训、Android培训-Java 学习过程记录_面向对象上2
- oracle表分析(2)
- S3C2440A的ADC和触摸屏接口
- 有些感悟,记录于此,防止遗忘:)
- Jquery ColorBox使用
- SharedPreferences的使用
- html细线表格
- Oracle数据的优化器有两种优化方法