When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Wednesday, November 22, 2000

Using ASP.NET/WebServices For UPS Shipping Quotes, Part 2
By Dan Anderson


In Part 1 we looked at how to create a Web Service. In this part we'll examine how to call that Web Service via an ASP.NET page!

- continued -

To call a Web Service from an ASP.NET page we need to create a proxy class DLL. This proxy class wraps all of the complex calls to a Web Service into a simple call that we can make from an ASP.NET page. Creating such a proxy class DLL is fairly simple (although a bit cryptic). It can be accomplished with a batch file:

webserviceutil /c:proxy /pa:http://localhost/asp2/ups.asmx?sdl /l:VB /n:nsUPS

vbc /out:bin\ups.dll /t:library /r:system.data.dll /r:system.web.services.dll
/r:system.net.dll /r:system.xml.serialization.dll ups.vb

The first line uses the WebServiceUtil.exe utility included in the .NET SDK. Basically, it creates a .VB file containing compiler pre-code, including references to all the required libraries and functions. The /c:proxy command indicates that we want to create a stub or proxy class of the web service from an SDL document. The SDL document is generated by the next portion of the command /pa:http://localhost/asp2/ups.asmx?sdl. The /pa: portion is the URI path to the web class file itself.

The /l:VB portion of the line simply says that the web service language used is Visual Basic. Finally, the /n:nsUPS gives the namespace to be used to refer to the web service. The namespace is similar to the "References" option used in Visual Basic. It declares the chunk of code functionality we wish to employ in a page or application.

The second line of the batch file, starting with vbc, is what actually generates the final web service DLL. First, vbc means Visual Basic Compiler. The next piece /out:bin\ups.dll defines the name of the dll we want generated, as well as the directory path to place it in. The /t:library defines the type of output we want the compiler to generate, which, in this case, is a DLL library. Next, the /r: directives ensure that required support libraries are included in the compilation process, much as we declared them via the Imports commands in the .asmx file itself. Finally, we define the source file to be compiled, which in this case is the ups.vb generated by the WebServiceUtil.exe utility.

It is generally recommended that you create a bin directory off of your site/application's root and place any web service dlls you create there. The PDC SDK version of ASP.NET gets a little picky and might, in some instances, require the Bin directory for dlls. There, we've compiled our web class. Now, let's use it!

We won't go into the entire file, because there is too much ground to cover. Instead, we're going to concern ourselves with the portion that involves the use of our new web service. The header of the client file looks like this:

<%@ Import Namespace="nsUPS" %>

Here, we have used the Import directive to load our new web service, using the namespace we defined for it when we compiled it. This creates an internal reference to our new web service. Down the page, in the ShowRate subroutine, you will see the following:

Dim D As New UPS
Dim PriceData=D.GetPrice(cSvcLevel,cRateChart,cShipperZIP, _
               cReceiverZIP,"US",cPkgWeight,cResidentialInd, _
               cCODInd,cSatPickupInd,cSatDelivInd,cPkgType)

Here, we have declared D as a new instance of our web service, after which we call the function in the web service (GetPrice), passing in the required parameters. The PriceData variable now holds the output of the web service, which is then displayed at the bottom of the page form. Our page, when first loaded, looks like this:

Web Services Screenshot

After entering the required information, it calls the web service, which updates the page to look like this:

Web Services Screenshot

Note that underneath the "Show Rate" button we now have the price for shipping the package provided from UPS. The files for this example are included below. If you have the PDC SDK version of .NET installed, give them a try!

Happy Programming!

  • By Dan Anderson


    Attachments:

  • Download the support code (in ZIP format)
  • Visit the ASP.NET Article Index!


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    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

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES