Saturday, March 21, 2009

We services tutorials part 2

Web Services have three basic platform elements: SOAP, WSDL and UDDI.
What is SOAP?
SOAP is a simple XML-based protocol to let applications exchange information over HTTP.
Or more simple: SOAP is a protocol for accessing a Web Service.
SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is a format for sending messages
SOAP is designed to communicate via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP is a W3C standard

What is WSDL?
WSDL is an XML-based language for describing Web services and how to access them.
WSDL stands for Web Services Description Language
WSDL is based on XML
WSDL is used to describe Web services
WSDL is also used to locate Web services
WSDL is a W3C standard

What is UDDI?
UDDI is a directory service where businesses can register and search for Web services.
UDDI stands for Universal Description, Discovery and Integration
UDDI is a directory for storing information about web services
UDDI is a directory of web service interfaces described by WSDL
UDDI communicates via SOAP
UDDI is built into the Microsoft .NET platform

-------------------------------------------------------------------------------------------------
Any application can have a Web Service component.
Web Services can be created regardless of programming language.
A Web Service Example
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:
<%@ WebService Language="VBScript" Class="TempConvert" %>Imports System
Imports System.Web.ServicesPublic Class TempConvert :Inherits WebService 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 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 functionend class
This document is saved as an .asmx file. This is the ASP.NET file extension for XML Web Services.
Example Explained
Note: To run this example, you will need a .NET server.
The first line in the example states that this is a Web Service, written in VBScript, and has the class name "TempConvert":
<%@ WebService Language="VBScript" Class="TempConvert" %>
The next lines import the namespace "System.Web.Services" from the .NET framework:
Imports System
Imports System.Web.Services
The next line defines that the "TempConvert" class is a WebService class type:
Public Class TempConvert :Inherits 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.
The only difference from a normal application is that this function is defined as a "WebMethod()".
Use "WebMethod()" to convert the functions in your application into web services:
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 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
Then, end the class:
end class
Publish the .asmx file on a server with .NET support, and you will have your first working Web Service.
Look at our example Web Service
ASP.NET Automates the Process
With ASP.NET, you do not have to write your own WSDL and SOAP documents.
If you look closer at our example Web Service, you will see that ASP.NET has automatically created a WSDL and SOAP request.

No comments: