What Is a Web Service?

   

What would you use a Web Service for? Well, that is a fair enough question. Web Services are used to program the Web. Web Services represents a way to abstract a Universal Resource Identifier (URI) and access it across the Web on another server. If this doesn't seem clear, keep reading and you will understand it as I explain and talk about Web Services.

The Simple Object Application Protocol (SOAP) is what Web Services use to communicate across the Internet.

What Is SOAP?

SOAP is used to send messages across the wire. One computer can use SOAP to send a block of data ”say, for instance, a billing record ”to another computer. When using SOAP, both computers understand the protocol, and can send and receive the data.

SOAP (Simple Object Access Protocol) starts with simple, and that's one of the key things it delivers. If you've ever worked with DCOM to communicate to remote servers, you know that DCOM is anything but simple ”as a matter of fact, it's pretty ugly.

SOAP is based on XML. The data that is carried in a SOAP package is always represented by XML. If you plan to do much with SOAP, you may want to take a look at the XML specification or do some reading and understand the basics of XML.

SOAP works with any operating system because it doesn't rely in any way on operating systems. It's a protocol on its own merit that dictates no hardware, operating system, or language specifications.

SOAP is also built on standards, and therefore can easily be implemented by anyone . First, it relies on HTTP to send data across the wire. Second, it relies on XML to represent the data. And third, it relies on the SOAP specification so that every implementer will be in compliance and able to communicate with all other implementers. You can get the SOAP specification at http://msdn.microsoft.com/workshop/xml/general/soapspec.asp.

SOAP Packages

SOAP data is sent in a well-organized manner as it goes across the Internet. This section shows you the hierarchy of SOAP packages.

Because all SOAP packages are sent within an HTTP message, the first part of a SOAP message is the HTTP header. Information in the section usually contains the domain name , the keyword POST , the Content-Type specification, and other optional information.

After the HTTP header comes the SOAP envelope. This encompasses the entire SOAP message. It's kind of like what's inside the box that arrives at your doorstep. It's all the important stuff you need (the actual data). The address label on the front of the box (the HTTP header) can almost always be discarded.

The SOAP envelope starts off with a SOAP header. This is different than the HTTP header. It doesn't contain information about the routing of the data (such as the domain name and the size of the content), but contains information related to the data, such as a transaction ID.

Why Is SOAP Important for Web Services?

Using SOAP for Web Services makes Web Services easy to use and powerful. SOAP enables Web Services to communicate across the Internet without having to worry about what operating system they are talking to and what language the other site is using.

If you have every programmed with VB5 or VB6 you will remember how easy it was to use an object that was registered or installed on a system. It was a matter of declaring the object and "newing" it as the following code shows:

 MyObject Obj = new MyObject  Obj.DoSomething() 

As you can see, after I created my object it was a simple matter to make method calls on that object. Wouldn't it be nice to have a programming model this simple for calling methods across the Web? Of course ”and that's what Web Services offer. The same type of simple object programming model that VB offered is now available using Web Services. You simply create a service object and call methods on it, as follows :

 MyService Ser = new MyService();  Ser.DoSomething(); 

As I said at the beginning of this chapter, Web Services might change how you develop and build Web applications. After seeing this new simplified ”yet powerful ”programming model, you are going tohave to agree that Web Services open things up for you unlike any other technology that has been introduced in recent years .

Why Are Web Services Useful?

Imagine you have some sort of an e-commerce Web site, and you have a partner that provides you with content. Or you might provide your partner with some sort of content or you have some other interaction. Web Services give you an easy way to integrate with partners . I will give some examples of this shortly.

Web Services are very easy to program. They are also based on standards. The fundamental standard on which they are based is HTTP; all the SOAP information uses this protocol as its basis. Then, the data is contained within a SOAP envelope, which is also a standard that has been submitted to the WC3. Within the SOAP envelope is XML. And XML is the standard that is becoming very popular and widely adopted for Internet data representation.

Another reason you would want to implement Web Services is because they can be easily upgraded on one server without affecting the applications that call them. If server A contains a Web Service, I can easily change it as long as I don't change the calling and return parameters. And I can do this without any knowledge or effect on server B, which calls methods in my Web Service on server A.

Real-World Scenarios for Using Web Services

I would like to talk for a minute about when you would use a Web Service. Although I can think of many examples, I'll cover just a few here. I'm sure that with a little effort you can come up with your own.

Suppose I have a Web site on which I want to serve up news content to users. The news content comes from a server located somewhere else on the Internet. A Web Service provides the easiest programming model for a Web application to retrieve and consume from across the Web.

Although I have carried out tasks before that pull in data and content from other Web servers, it hasn't always been easy. It has taken me several days to do this, then several more days to debug the material I received, and making changes was sometimes difficult. In the end, this process might have taken me anywhere from four to five days of programming. With a Web Service I can consume content from a remote server in about two hours.

Credit card authorization of course comes to mind. A Web Service makes the ideal method of doing credit card authorization. From one server you can easily hit another server and authorize a credit card with just several lines of programming code.

Centralization of user information is another option that Web Services provide. You might have a user who has a set of information that is associated with that user. A Web Service can enable multiple Web Services to retrieve and use information about a given user . Of course this assumes that there is proper security clearance and the proper authorization credentials.

Web Services enable you to create a fantastic ad server. Imagine being able to provide user information, such as a user's preferences, and an ad server serves up a targeted ad toward that particular user. Say, for instance, that I am on a Web site and somehow I have let it be known that I like golf. As a matter of fact, I may have indicated on the Web site that I am looking for a new set of clubs. Rather than just rotate through a bunch of ads, a Web application can call a Web Service and let the Web Service know that the user likes or has an interest in golf, and the Web Service serves up a targeted ad with golf clubs or golf accessories.

   


Special Edition Using ASP. NET
Special Edition Using ASP.Net
ISBN: 0789725606
EAN: 2147483647
Year: 2002
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net