Learning Center
Plans & pricing Sign in
Sign Out
Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>



  • pg 1

ASP.NET XML Web services enable you to remotely access the properties and methods
of classes across a network. They are an important part of the Microsoft vision of the
programmable Web.
The Web, as it currently exists, is designed around humans browsing Web pages through
a We browser. Typically, the only way to present information through the Internet is to
build a Web page designed to be consumed by human eyes.
However, in many situations, exposing information to an application makes more sense
than exposing it to a human.
Consider, for example, the process of buying a book online. Currently to buy a book you
must complete each of the following steps

   1.   Find a Web site that sells the book you want for the cheapest price
   2.   Log in to the web site with your username and password
   3.   Select a shipping method for the book
   4.   Pay for the book by entering your credit card number.

XML Web Services have the potential to alter the manner in which each step is

When you enter a credit card number to pay for a book, the Web site must communicate
with a credit card processor to authorize your credit card purchase. The credit card
number must be transmitted over the Web, and the purchase must be authorized or
declined. All these transactions must be accomplished in real-time. There is no standard
way of completing this process. To communicate with each major credit card processor,
you must implement different proprietary software.

XML Web services have the potential to standardize the process of authorizing credit
cards. Imagine a credit card authorization Web service. The Web service would have an
authorization method to accept a credit card number, an expiration date, and a purchase
amount. When the method is invoked, it would return either approved or declined.
When purchasing a book, you must select a shipping method. To get a list of shipping
options and prices for each option, the Web site must communicate with one or more
shipping services. Again, there is no standard way of completing this process. The
method for communicating with Federal Express is different than the method for
communicating with United Parcel Service.

Now image a shipping Web service. You would transmit an origin and destination
address to the service, and it would return a list of whipping options with different prices.

Again, imagine a Web service simplifying this process. In this case, it would be a user
registration Web service. Whenever you visit a Web site, it could communicate with the
user registration Web service to verify your identity. You would pass a username and
password to the Web service, and it would return a value indicating whether the
username and password combination is valid.

XML Web services facilitate communication among different Web sites and different
applications. Because Web services are built on open standards—such as HTTP,XML
and SOAP(Simple Object Access Protocol)—they enable communication in a platform
independent way.

Because Web services are based on open standards, an ASP.NET Web site can use Web
services to communicate with a Web site created on a different platform, such as Java.

Another important application of Web services is communication with applications
running on legacy systems.

<add name="HttpGet"/>
<add name="HttpPost"/>

Put in Bin Folder of your project
Imports System.Web.Services
Imports System

Public Class TemperatureService : Inherits WebService

   <WebMethod()> Public Function ToCelsius(ByVal TF As Double) As Double
     Return (5 / 9) * (TF - 32)
   End Function

   <WebMethod()> Public Function ToFahrenheit(ByVal TC As Double) As Double
     Return (9 / 5) * TC + 32
   End Function

<%@ WebService Language="vb" Codebehind="TemperatureService.asmx.vb"
Class="jat14.TemperatureService" %>

<WebMethod()> Public Function ToCelsius(ByVal TF As Double) As Double

The <WebMethod()> expression applies a custom attribute, named WebMethod, to the
ToCelsius function. The WebMethod custom attribute exposes the function to the world
so that it can be accessed through the Web service.

.asmx extension

Invoking an XML Service with HTTP-Get
HTTP-Get is the standard HTTP Protocol for transmitting requests for URLs or posting a
form with METHOD=”Get”. You could invoke the ToCelsius method of the
TemperatureService Web service as follows

Invoking an XML Web Service with HTTP-Post

<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name=ProgId content=VisualStudio.HTML>
<meta name=Originator content="Microsoft Visual Studio .NET 7.1">
<body MS_POSITIONING="FlowLayout">

<form method="post" action="/misbd470/jat14/TemperatureService.asmx/ToCelsius">
<input name=TF value="32">
<input type="submit" value="Convert!">


HTTP-Post is the standard HTTP protocol for transmitting form data submitted with

Posting the form would invoke the ToCelsius method of the TemperatureService Web
Invoking an XML Web Service with SOAP
The Simple Object Access Protocol enables you to transmit more complex types of
messages across a network. You can transmit data types with SOAP that you cannot
transmit using either HTTP-Get or HTTP-Post. For example, you can use SOAP to
transmit DataSets, custom classes, and binary files.

SOAP is an XML-based protocol backed by a number of large companies including
Microsoft, IBM, and Ariba. A SOAP message contains an envelope section that contains
the data to be transported
Accessing an XML Web Service Through a Proxy Class

You can access a Web service from within an application by creating a Web service
proxy class. This type of proxy class is a local representation of the properties and
methods of a remote Web service class.

After you create a proxy class, you can treat the class exactly like any other .Net
Framework class. For example, image that the TemperatureService Web service is
hosted at an Internet service provider located in central Borneo. After you create a proxy
class, you can invoke the methods of the remote Web service class within your
application as though the class were located on your computer.

To top