W3Schools

home HOME

Web Services Basic
WS Home
WS Intro
Why WS?
WS Platform
WS Example
WS Use
WS Summary

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Forum

Helping W3Schools

Web Service Example

back next

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="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 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 VBScript and the class name is "TempConvert":

<%@ WebService Language="VBScript" 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 WebService 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 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

The last thing to do is to end the class:

end class

If you save this as an .asmx file and publish it on a server with .NET support, you should have your first working Web Service. Like 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 on our example Web Service. You will see that the ASP.NET has automatically created a WSDL and SOAP request.


back next


Ektron CMS400.NET Ektron - What do you want your website to do?
The Ektron Intranet
Take the video tour

The Ektron Intranet lets you do everything you need to do on your corporate intranet and everything you want to do... all with just one application.

What can you do with the Ektron Intranet?

Ektron

Navigate through content, documents, assets, colleagues and workgroups quickly and intuitively with enterprise search

Ektron

Communicate with friends and colleagues with forums, message boards and corporate blogging using the new Social Networking Platform

Ektron

Utilize the extensive out-of-the box features or customize your site through Ektron CMS400.NET's open architecture

Ektron

Promote collaboration in your organization through project workspaces where others can efficiently find information and work together

Ektron

Author/edit content, manage navigation, menus, audit trails, workflow and approvals with the best in breed Content Management

See why there are 20,000+ Ektron integrations worldwide.

Take the Video Tour TAKE THE VIDEO TOUR
Take the Video Tour or download a FREE TRIAL today.



Jump to: Top of Page or HOME or Printer Friendly Printer friendly page

W3Schools provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2008 by Refsnes Data. All Rights Reserved.

Validate Validate W3C-WAI level A conformance icon W3Schools was converted to XHTML in December 1999