SummaryAs you have seen, it's easy to create ASP.NET server controls. They give you the chance to create reusable server controls that will make your job as a developer much easier.
You've seen two aspects of server controls: creating them and using them. We created the controls in a C# Web Control Library, and they were consumed and
|
Chapter 14. Web ServicesIn this chapter
Web Services are one of the most exciting things to be introduced to .NET. Web Services have the potential for changing everything that you do in your Web development. They can simplify your development
This chapter talks about Web Services showing you what they are, what you would use them for, and walking you through their creation and use. |
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
SOAP PackagesSOAP 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
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
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
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
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
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
Real-World Scenarios for Using Web ServicesI 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
Although I have carried out
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
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
|