ASPnews Home





ASP Directory


About Us

Search ASPnews:
Internet Lists
Internet News
Internet Resources
Linux/Open Source
Personal Technology
Small Business
Windows Technology
xSP Resources
Corporate Info
Tech Jobs
E-mail Offers
Be a Commerce Partner
Cheap Plane Tickets
Digital Camera Review
Register Domain Name
Memory Flash Cards
Online Education
Remote Access
Advertising Trucks
Online Degrees
Best Digital Camera
Cheap Web Hosting
Digital Camera Review

ASPnews Focus
Top News:
» SOAs So Close, Yet So Far

» Why SaaS Is Making a Comeback

» Join the Discussion:'s industry forums

» More ASP News

TOP 50
Top 20 Providers
 & Top 30 Enablers
Free Newsletter!

ASPnews Shortcuts
Week's Top News

ASP News at

Industry Events

Discussion Forums

Industry Basics

Site Guide

FREE activePDF Download: Add Dynamic PDF Generation to Your Applications


Dev: Building Distributed Apps? Use XML Web Services, Not .NET Remoting (Mostly)
By Paul Kimmel

December 16, 2004

Continued from Page 2

When you run a Web service, VS.NET creates a default Web page. This page, generally just for testing purposes, offers a simple interface for adding parameters and invoking the Web methods. To test the Web service:

  1. Click the hyperlinks. You’ll see one for each WebMethod (see Figure 1).
  2. Provide any parameters, if required.
  3. Click the Invoke button (see Figure 2).

Click here for a larger image.

Figure 1: Each WebMethod is listed in the generated test page.

Click here for a larger image.

Figure 2: Click the Invoke method to test the selected WebMethod.

The result of invoking a Web method using the test interface is XML (see Figure 3). (This should be your first clue that Web services are not meant to be used in this manner, only tested.)

Click here for a larger image.

Figure 3: When you invoke a Web method using the test page, XML is returned.

I hope it is clear from the example that all a Web service and its Web methods are are a class and methods that convert the values passed to and from into XML text. The reason for this is that text and the World Wide Web are the oldest and best of friends. Text is passed easily across the Internet and XML makes that text self-describing.

If programmers had to write parsers to decipher all of the XML mumbo jumbo, XML Web services would represent only a partial solution. However, the .NET framework knows how to easily produce and consume XML Web services and convert XML back into usable code elements. This means that, in practice, you just write code to produce and consume XML Web services and leave the hard part of serialization and HTTP to the .NET Framework.

Consuming a Web Service

When you want to consume a Web service, you actually use some pretty advanced technologies. You use UDDI (Universal Discovery and Description Indexes), WSDL (whizdahl, or Web services Discover Language), and SPROXY. UDDI is a directory service that helps identify Web services. WSDL helps figure out what each service offers, and SPROXY uses the CodeDOM to generate proxy classes, which in turn makes it easy to consume the services a Web service offers. Collectively, these technologies mean all you as a Web service consumer have to do is write code to create instances of the classes and invoke methods offered by the service.

To consume the sample Web service with the Hello World Web method, take the following steps:

  1. Add any kind of project to a new solution or the solution containing the sample Web service project. It doesn’t matter which, but I added a console application to the same solution.

  2. Select the new project, and then select Project|Add Web Reference. This will open the Add Web Reference dialog (see Figure 4). This is your key to finding Web services on your PC or anywhere else.

  3. Select Web services on the local machine. If you want a Web service produced by someone else, select the UDDI Directory option (see Figure 4).

  4. Selecting the first option results in a search for .asmx files on the IIS Server on your PC. (I haven’t tried this with the Apache Web server, but one would hope the result is the same.)

  5. From the list of services, pick the one you just created and click the Add Reference button (see Figure 5).

Click here for a larger image.

Figure 4: The Add Web Reference dialog helps you find local Web services or those anywhere in the world.

Click here for a larger image.

Figure 5: Add a reference to the desired Web service.

After the last step, you are ready to invoke the Web methods exposed by this service.

Essentially, adding a Web reference means that WSDL, in conjunction with SPROXY, will generate some code. This code will include a namespace and a wrapper class. The wrapper class will condense the code needed to invoke each Web method into a simple method call. SPROXY also uses Reflection to create local versions of composite returned types. For example, if the consumed Web method returns a Customer class, SPROXY will generate a flattened, properties-only version of that class. In generated types, properties are flattened into public fields and other elements are removed. What you end up with is basically a structure, but types defined by the Web services producer also are effectively available in your consumer code. Without the proxy classes, your code would not recognize types defined by the Web service and would not compile.

Some developers mistakenly deploy the assemblies that contain the description of objects returned by Web methods to client machines. This is a critical mistake. By deploying the assemblies on client machines, customers can use free tools such as Anakrino or Reflector to disassemble and decompile these assemblies and learn everything about your business. Don’t distribute these assemblies. Instead, permit consumers — whether internal or external — to see only the SPROXY-generated composite types. The effect is two-fold: Consumers can’t disassemble your business code, and producers are reminded to create Web services that provide macro-level behaviors that satisfy consumer needs.

Page 4: Invoking an Imported Web Method

Go to page: Prev  1  2  3  4  5  Next  

Email this Article
View Printable Version
Back to Strategies


Featured Links
Learn the secrets of the popular search engines!
Free Web Hosting Buyer's Guide -- Click Here!
Enhance your Web site with the Dynamic HTML HierMenus Code

JupiterWeb networks:

Search JupiterWeb:

Jupitermedia Corporation has three divisions:
Jupiterimages, JupiterWeb and JupiterResearch

Copyright 2005 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | Shopping | E-mail Offers

Give us your Feedback