spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column112


JScript .NET, Part VI: Creating IE Web Services

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Scripting Web Service Consumption

We have explained in Column 106 how to consume foreign Web services through Microsoft Internet Explorer. In this column, we show you how to consume your own Web services. Put your Web services (asmx files) in c:\inetpub\wwwroot\Webreference. Then, when you access the services in your scripts, you refer to their directory as http://localhost/Webreference.

You need to have three JavaScript functions for each Web service you consume:

  • The init() function assigns a short name to the Web service URL
  • A function to call the Web service with the appropriate parameters
  • A function to display the results

The init() function can be shared among Web services. It is invoked upon loading of the page, onload=init(). We call the webservice behavior's useService() method to assign short identifiers to the Web service's rather-long URL. We call the Add Web service by "simpleCalcWebService" and the IsPrime Web service by "isPrimeNumberWebService":

function init() {
  myWebService.useService("
    http://localhost/Webreference/checkIsPrime.asmx?WSDL",
    "isPrimeNumberWebService");
  myWebService.useService("http://localhost/Webreference/
    simpleCalc.asmx?WSDL",
    "simpleCalcWebService");
}

The function addNumbers() is invoked when the Add button is clicked. It calls the webservice behavior's callService() method. The parameters are: (i) the function that handles the result display, (ii) the Web service command, "add", (iii) the first number, and (iv) the second number:

function addNumbers(a, b) {
  myWebService.simpleCalcWebService.callService
    (addResult, "add", first.value, second.value);
}

Similarly, isPrimeNumber() is called when the Click here to check if prime button is clicked. It calls the Web service with three parameters: (i) the function to handle the result, isPrimeNumberResult, (ii) the Web service request, IsPrime, and (iii) the parameter expected by the Web service, testValue.value:

function isPrimeNumber() {
  myWebService.isPrimeNumberWebService.
    callService(isPrimeNumberResult, "IsPrime",
    testValue.value);
}

We use DIV elements to display results of both Web services. Once a result is ready, we update the innerHTML property of the appropriate element. Here is how we update the result of the Add Web service:

function addResult(result) {
  theResult1.innerHTML = result.value;
}

We embed the result of the IsPrime Web service within a descriptive message:

function isPrimeNumberResult(result) {
  theResult2.innerHTML = "The number " + testValue.value +
    (result.value ? " is" : " is not") + " a prime number";
}

Next: A Final Word

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: June 17, 2002
Revised: June 17, 2002

URL: http://www.webreference.com/js/column112/6.html