Παράδειγμα Web Services
- Προηγούμενη Σελίδα Πλατφόρμα WS
- Επόμενη Σελίδα Χρήση WS
Any application can have a Web Service component.
The creation and programming of Web Services are unrelated to the type of programming language.
An example: ASP.NET Web Service
In this example, we will use ASP.NET to create a simple Web Service.
<%@ WebService Language="VB" Class="TempConvert" %> Imports System Imports System.Web.Services Public Class TempConvert : Inherits WebService <WebMethod()> Δημόσια Λειτουργία FahrenheitToCelsius (ByVal Fahrenheit As Int16) As Int16 Dim celsius As Int16 celsius = ((((Fahrenheit) - 32) / 9) * 5) Επιστροφή celsius Κλείσιμο Λειτουργίας <WebMethod()> Δημόσια Λειτουργία CelsiusToFahrenheit (ByVal Celsius As Int16) As Int16 Dim fahrenheit As Int16 fahrenheit = ((((Celsius) * 9) / 5) + 32) Επιστροφή fahrenheit Κλείσιμο Λειτουργίας Κλείσιμο Κλάσης
This document is an .asmx file. It is the file extension for ASP.NET used in XML Web Services.
To run this example, we need a .NET server
The first line of this document indicates that this is a Web Service written in VB, with the class name "TempConvert".
<%@ WebService Language="VB" Class="TempConvert" %>
The following code lines import the namespace "System.Web.Services" from the .NET framework.
Imports System Imports System.Web.Services
The following line defines the "TempConvert" class as a WebSerivce class:
Public Class TempConvert : Inherits WebService
The next steps are basic VB programming. This application has two functions. One converts Fahrenheit to Celsius, and the other converts Celsius to Fahrenheit.
The only difference from a regular application is that this function is defined as "WebMethod".
Please use "WebMethod" to mark the function in the application you want to become web services.
<WebMethod()> Δημόσια Λειτουργία FahrenheitToCelsius (ByVal Fahrenheit As Int16) As Int16 Dim celsius As Int16 celsius = ((((Fahrenheit) - 32) / 9) * 5) Επιστροφή celsius Κλείσιμο Λειτουργίας <WebMethod()> Δημόσια Λειτουργία CelsiusToFahrenheit (ByVal Celsius As Int16) As Int16 Dim fahrenheit As Int16 fahrenheit = ((((Celsius) * 9) / 5) + 32) Επιστροφή fahrenheit Κλείσιμο Λειτουργίας
Τελευταία πράξη που πρέπει να κάνετε είναι να κλείσετε τη λειτουργία και την κλάση:
Κλείσιμο Λειτουργίας Κλείσιμο Κλάσης
Αν αποθηκεύσετε αυτό το αρχείο ως αρχείο .asmx και το δημοσιεύσετε σε διακομιστή που υποστηρίζει το .NET, θα έχετε τον πρώτο λειτουργικό Web Service.
Αυτόματη Επεξεργασία του ASP.NET
Με το ASP.NET, δεν χρειάζεται να γράψετε ούτε ένα WSDL και SOAP έγγραφο.
Αν μελετήσετε προσεκτικά αυτό το παράδειγμα, θα δείτε ότι το ASP.NET δημιουργεί αυτόματα το WSDL και το αίτημα SOAP.
- Προηγούμενη Σελίδα Πλατφόρμα WS
- Επόμενη Σελίδα Χρήση WS