Web Service Example>>

Any application can have a Web Service component.

Web Services can be created regardless of programming language.


An example ASP.NET Web Service

In this example we 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()> 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.


To run this example you will need a .NET server.

The first line in this document that it is a Web Service, written in VB and the class name is "TempConvert":

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

The next lines imports 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 WebSerivce class type:

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.

The only difference from a normal application is that this function is defined as a "WebMethod".

Use "WebMethod" to mark the functions in your application that you would like to make into web services.

<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.


ASP.NET automates the process

With ASP.NET you do not have to write your own WSDL and SOAP documents.

If you look closer on our example Web Service. You will see that the ASP.NET has automatically created a WSDL and SOAP request.


<< Back








   



MSN Nick Name



More Resources...





Most Viewed Services:
  1. HTML Tutorial
  2. XHTML Tutorial
  3. CSS Tutorial
  4. Javascript Tutorial
  5. DHTML Tutorial
  6. VB Script
  7. TCP/IP Tutorial
  8. ADO Tutorial
  9. MYSQL Tutorial
  10. ASP Tutorial
  11. AJAX Tutorial
  12. CFML Tutorial
  13. PHP Tutorial
  14. WML Tutorial
  15. FLASH Tutorial
  16. XML Tutorial
  17. RSS Tutorial
  18. SQL Tutorial
  19. HTML Articles
  1. Javascript Articles
  2. PHP Articles
  3. SEO Articles
  4. Web Design Articles
  5. SEO Tips
  6. Web Design Tips
  7. Articles
  8. CSS
  9. CSS Tips
  10. HTML Tips
  11. JAVASCRIPT Tips
  12. MYSQL Tips
  13. PHP Tips
  14. Money
  15. Tutorials
  16. Web Hosting



  • Home
  • Web Directory
  • Top Directoriers
  • Webmaster Directories
  • Contact
  • © Copyright 2006 All Rights Reserved By CodeDcode.Com