O'Reilly logo

Object-Oriented Programming with Visual Basic .NET by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.1. Writing a Web Service

Zip code verification is a simple but useful example of a service that can be provided over the Web. The sole purpose of this web service is to confirm that a zip code for a given city is valid. Imagine it as just one of several services offered to online businesses to authenticate shipping and billing addresses and minimize fraud. It also solves a real-world problem: someone in California makes an online purchase from a web site in California, provides a California address, but uses a zip code from Texas. Chances are that the order will arrive, albeit late, to the intended address. However, by specifying an improper zip code, the purchaser has circumvented paying sales tax.

10.1.1. The Web Service Class

Any class that wishes to become a web service must have at least one method that is decorated with a WebMethod attribute. This is the bare minimum requirement for running a web service.

There is also a WebService attribute that is used at the class level, as in:

<WebService(Namespace:="http://www.mydomainhere.com/")> _
Public Class ZipService

Although the WebService attribute is not a runtime requirement, it should be used nonetheless to provide a namespace that uniquely identifies the web service on the Internet. Usually, a company uses its domain to form the namespace. However, the namespace itself does not have to conform to a site that can be reached over the Internet. If a namespace is not given, http://tempuri.org/ is used by default. (This ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required