spacer
Yehuda Shiran July 3, 2002
Extending a Class to a Web Service
Tips: July 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Here is what you need to do to convert a class to a Web service:

  • Import the System.Web.Service namespace
  • Add a directive line, specifying the class's language and namespace
  • Derive the class from the .NET Class Library's WebService class
  • Add the attribute WebMethodAttribute to each method you want to expose as a Web service method
  • Put your code in a file with the extension .asmx and save in your Web server area.

Let's apply the main steps from above to our PrimeNumbers class. The directive line is the first line of the file and looks like this:

  <%@ WebService Language="JScript" class="PrimeNumbers" %>
You derive the class from the WebService class by extending it. The WebService class includes a lot of methods that are needed for deploying a Web service. Basing your class on the WebService class provides you with these methods for free. You need focus only on your unique value-adding business logic. Here is how you extend WebService to PrimeNumbers:

  public class PrimeNumbers extends WebService {
The location of your Web service is on your Web server. If your Web server is IIS and your file is checkIsPrime.asmx for example, you can save it in a directory under c:\inetpub\wwwroot. For example:

  c:\inetpub\wwwroot\Webreference\checkIsPrime.asmx
From now on, you can refer to this Web service as:

  http://localhost/Webreference/checkIsPrime.asmx
To learn more about JScript .NET, go to Column 112, JScript .NET, Part VI: Creating IE Web Services.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business