Archive for December, 2007

CHAPTER 20 WEB SERVICES // Always create (Post office web site)

Tuesday, December 11th, 2007

CHAPTER 20 WEB SERVICES // Always create a parameter array $params = array(); // Create a new SOAP client $client = new soapclient(”http://localhost/book/20/boxing.php”); // Execute the remote method retrieveBio() $boxer = $client->call(’retrieveBio’, $params); // Parse the returned associative array $name = $boxer[”name”]; $age = $boxer[”age”]; $bio = $boxer[”bio”]; // Output the information echo “$name ($age years)
$bio”; ?> Executing the client results in the following output: Muhammed Ali (61 years)
Ali held the World heavyweight title three times throughout his career. Generating a WSDL Document You ll need to generate a Web Services Definition Language (WSDL) document in order to offer clients the opportunity to call methods via a proxy as was demonstrated in Listing 20-7. Doing so via NuSOAP is surprisingly easy, accomplished with few modifications to the servers demonstrated thus far. Two additional methods must be called to initiate WSDL configuration and specify the WSDL namespace: configureWSDL() and schemaTargetNamespace(), respectively. In addition, because PHP is a loosely typed language, both the input and returned values must be defined using XML Schema, which hints at the datatype requirements. Listing 20-11 is a modified version of Listing 20-7, offering WSDL generation support. Listing 20-11. Generating WSDL configureWSDL(’boxing’, ‘urn:boxing’); // Designate the WSDL namespace $server->wsdl->schemaTargetNamespace = ‘urn:boxing’;
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

498 CHAPTER 20 WEB (Web host forum) SERVICES Contacting the

Monday, December 10th, 2007

498 CHAPTER 20 WEB SERVICES Contacting the Web Service using this client results in a random quote being retrieved from the quotation database table. Sample output follows: “It’s easy to do anything in victory. It’s in defeat that a man reveals himself.”, Floyd Patterson (1935) Returning an Array You ll often want to retrieve various items of information from a Web Service, such as a profile of a given fighter in the boxing quote example. One of the easiest ways to do so is by returning an array back to the client. This is accomplished using PHP s default functionality, returning the array just like any other variable. This is demonstrated in Listing 20-10. Listing 20-10. Returning an Array to the Client register(”retrieveBio”); // Define the retrieveBio() function function retrieveBio() { // Assume that this information was retrieved from a database $boxer[”name”] = “Muhammed Ali”; $boxer[”age”] = 61; $boxer[”bio”] = “Ali held the World heavyweight title three times throughout his career.”; return $boxer; } $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ‘’; $server->service($HTTP_RAW_POST_DATA); ?> The client can contact the retrieveBio() function, and parse the array information using the list() statement, like so: Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

CHAPTER 20 WEB SERVICES Listing 20-8. The (Web site designers)

Sunday, December 9th, 2007

CHAPTER 20 WEB SERVICES Listing 20-8. The Boxing Quote Web Service (boxing.php) register(”getRandQuote”); // Automatically execute any incoming request $server->service($HTTP_RAW_POST_DATA); ?> All that s left is to create a client capable of consuming our service. This client is offered in Listing 20-9. Listing 20-9. A Boxing Web Service Client call(’getRandQuote’); echo “

Your random boxing quotation of the moment:
$quote

“; ?>
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

496 CHAPTER 20 WEB SERVICES // Point (Web hosting provider)

Saturday, December 8th, 2007

496 CHAPTER 20 WEB SERVICES // Point to the WSDL file $wsdl = “googleapi/GoogleSearch.wsdl”; // Create a new soapclient object $client = new soapclient($wsdl, ‘wsdl’); // Create a proxy so you can call the Google methods directly $proxy = $client->getProxy(); // Suppose user enters keyword via Web form (would be via $_POST) $keyword = “freplace”; // Pass keyword to doSpellingSuggestion() method. $suggestion = $proxy->doSpellingSuggestion($key, $keyword); // Prompt user to consider searching using suggested term echo “Supplied search term not found. Perhaps you meant $suggestion?”; ?> Executing this example produces the same output as that found from Listing 20-6. The difference is that making the remote method calls in this fashion is much more convenient. Publishing a Web Service Of course, you might want to not only consume Web Services, but also publish them. After all, how better to offer your vast compilation of boxing quotes to the world? In this section, you ll learn how to use NuSOAP to create a Web Service that does just this. For starters, you need to create a PostgreSQL table that hosts the quotes. Although a realworld implementation would involve multiple tables, this example is purposely kept simple, with everything encapsulated in a single table named quotation: CREATE TABLE quotation ( id SERIAL, boxer VARCHAR(30) NOT NULL, quote TEXT NOT NULL, year DATE NOT NULL, PRIMARY KEY(id) ); Assume that this table has been packed with profound statements from the world s greatest fighters. Next, you need to create the Web Service. The commented script is offered in Listing 20-8.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

CHAPTER 20 WEB SERVICES // Create a

Friday, December 7th, 2007

CHAPTER 20 WEB SERVICES // Create a new soapclient object $client = new soapclient($wsdl, ‘wsdl’); // Suppose user enters keyword via Web form (would be via $_POST) $keyword = “freplace”; // Which parameters should be passed to the doSpellingSuggestion() method? $input = array(’phrase’ => $keyword, ‘key’ => $key); // Call the doSpellingSuggestion() method $suggestion = $client->call(’doSpellingSuggestion’, $input); // Prompt user to consider searching using suggested term echo “Supplied search term not found. Perhaps you meant $suggestion?”; ?> Executing this example produces the following output: Supplied search term not found. Perhaps you meant fireplace? Of course, by itself this example isn t particularly useful. However, it would be trivial to execute Google s doSpellingSuggestion() method should an attempt to search your internal Web site produce zero results. The empty link found in the output could be completed to take the user back to your search engine, this time automatically inputting the suggested keyword. You may be wondering how the array keys and method name were determined. After all, you can t just make up these names. You can determine this in either of two ways: review the WSDL file, which breaks down each method and its corresponding parameters, or append ?wsdl to the end of the service URL for NuSOAP-created services. Creating a Method Proxy You can also access the Web Service s methods directly, as if the service were a local class library. This is done by creating a proxy via the getProxy() method. Listing 20-6 has been revised to do exactly this. Listing 20-7 offers the revised script. Listing 20-7. Using NuSOAP s Proxy Class Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

494 CHAPTER 20 WEB SERVICES Consuming a (Ecommerce web host)

Thursday, December 6th, 2007

494 CHAPTER 20 WEB SERVICES Consuming a Web Service Rather than go through the motions of creating a useless Hello World type of example, it seems more practical to create a client that actually consumes a live, real-world Web Service. As mentioned earlier in the chapter, several large organizations have already started offering public Web Services, including Google, Yahoo!, and Microsoft. The particularly compelling Google Web Service provides a solution for searching the Web via its databases without having to actually visit the Web site. For example, you could use the Web Service in conjunction with any SOAP-capable language (PHP, C#, Perl, or Python, to name a few) to build a custom interface for searching the site, be it the Web, desktop, or command line. However, numerous other interesting features are available to developers, such as the ability to take advantage of Google s amazing spell-checker (which appears at the top of any search results page if the engine thinks that you potentially misspelled a search term). The next several examples take advantage of Google s Web Service, demonstrating both NuSOAP s capabilities and a number of interesting features offered by this Web Service. Before you can execute these examples, however, you need to go to the Google Web Service site (http://www.google.com/apis/) and obtain a license key by registering for a free account. It only takes a moment to do, so go ahead and take care of that now. You also need to download the developer s kit (available via the aforementioned URL), because the WSDL file is bundled into it. As you ve done for previous third-party packages in this chapter, place the unzipped package in a location where the WSDL file is easily accessible by a PHP script, or just copy the WSDL file into the same directory as the script, because that s the only file you ll need from this package. Once you have completed these two steps, proceed to the next section. Caution At present, Google s Web Service is limited to 1,000 queries per day. So while it s great for experimentation or personal use, don t plan to integrate it into your corporate Web site anytime soon. Also, be sure to read through the API terms of service if you plan to use the Web Service in any way: http:// www.google.com/apis/api_terms.html. Listing 20-6 offers the first example, which uses Google s spell-checker method, doSpellingSuggestion(), to offer suggestions for the misspelled word fireplace. Listing 20-6. Consuming Google s Web Service We recommend high quality webhost to host and run your jsp application: christian web host services.

Web design portfolio - CHAPTER 20 WEB SERVICES WSDL generation

Wednesday, December 5th, 2007

CHAPTER 20 WEB SERVICES WSDL generation and importing: NuSOAP will generate a WSDL document corresponding to a published Web Service and can import a WSDL reference for use within a NuSOAP client. A proxy class: NuSOAP can generate a proxy class that allows for the remote methods to be called as if they were local. HTTP proxying: For varying reasons (security and auditing are two), some clients are forced to delegate a request to an HTTP proxy, which in turn performs the request on the client s behalf. That said, any SOAP request would need to pass through this proxy rather than directly query the service server. NuSOAP offers basic support for specifying this proxy server. SSL: NuSOAP supports secure communication via SSL if the CURL extension is made available via PHP. All of these features are discussed in further detail throughout this section. For starters, however, you need to install NuSOAP. This simple process is introduced next. Note NuSOAP was originally known as SOAPx4, and in fact is a rewrite of the original project. The name was changed in accordance with an agreement by the project author (Dietrich Ayala) and the company NuSphere, which had at one point sponsored development. Installing NuSOAP Installing NuSOAP is really a trivial affair, done in three steps: 1. Download the latest stable distribution from http://dietrich.ganx4.com/nusoap/. 2. Extract the package contents to a location convenient for inclusion from a PHP script. Consider placing third-party classes within an aptly named directory located within the PHP_INSTALL_DIR/includes/ directory this is for convenience reasons only, and isn t a requirement. 3. Include the NuSOAP class (nusoap.php) within your script: require(’nusoap/nusoap.php’); That s it! You re ready to begin using NuSOAP. Caution At the time of writing, there was a naming conflict between the NuSOAP class and that found in PHP 5 s native SOAP extension (introduced later in this chapter). While the intention of introducing NuSOAP is to offer those readers not yet running PHP 5 the opportunity to take advantage of SOAP-driven Web services, if for some reason you prefer to use NuSOAP over the SOAP extension, you ll need to disable the native extension.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

492 CHAPTER 20 WEB (Web hosting unlimited bandwidth) SERVICES Keep in

Tuesday, December 4th, 2007

492 CHAPTER 20 WEB SERVICES Keep in mind that SOAP is only responsible for defining the construct used for the exchange of messages; it does not define the protocol used to transport that message, nor does it describe the features or purpose of the Web Service used to send or receive that message. This means that you could conceivably use SOAP over any protocol, and in fact could route a SOAP message over numerous protocols during the course of transmission. A sample SOAP message is offered in Listing 20-5 (formatted for readability). Listing 20-5. A Sample SOAP Message “My main objective is to be professional but to kill him.”, Mike Tyson (2002) If you re new to SOAP, it would certainly behoove you to take some time to become familiar with the protocol. A simple Web search will turn up a considerable amount of information pertinent to this pillar of Web Services. Regardless, you should be able to follow along with the ensuing discussion quite easily, because the first SOAP-related project introduced, NuSOAP, does a fantastic job of taking care of most of the dirty work pertinent to the assembly, parsing, submission, and retrieval of SOAP messages. Following the NuSOAP discussion, PHP 5 s new SOAP extension is introduced, showing you how you can create both SOAP clients and servers using native language functionality. NuSOAP NuSOAP is a powerful group of PHP classes that makes the process of consuming and creating SOAP messages trivial. Written by Dietrich Ayala, NuSOAP works seamlessly with many of the most popular SOAP server implementations, and is released under the LGPL. NuSOAP offers a bevy of impressive features, including: Simplicity: NuSOAP s object-oriented approach hides many of the details pertinent to the SOAP message assembling, parsing, submission, and reception, allowing the user to concentrate on the application itself.
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

CHAPTER 20 WEB SERVICES Jane Austen Alberto (Web hosting providers)

Monday, December 3rd, 2007

CHAPTER 20 WEB SERVICES Jane Austen Alberto Moravia Ernest Hemingway You can also use XPath functions to selectively retrieve a node and its children based on a particular value. For example, suppose you want to retrieve all book titles where the author is named Ernest Hemingway : xpath(”/library/book[author=’Ernest Hemingway’]”); echo $book[0]->title; ?> This example returns: The Sun Also Rises SOAP The postal service is amazingly effective at transferring a package from party A to party B, but its only concern is ensuring the safe and timely transmission. The postal service is oblivious to the nature of the transaction, provided that it is in accordance with the postal service s terms of service. As a result, a letter written in English might be sent to a fisherman in China, and that letter will indeed arrive without issue, but the recipient would probably not understand a word of it. The same holds true if the fisherman were to send a letter to you written in his native language; chances are you wouldn t even know where to begin. This isn t unlike what might occur if two applications attempt to talk to each other across a network. Although they could employ messaging protocols like HTTP and SMTP in much the same way that we make use of the postal service, it s quite unlikely one will be able to say anything of discernible interest to the other. However, if the parties agree to send data using the same messaging language, and both are capable of understanding messages sent to them, then the dilemma is resolved. Granted, both parties might go about their own way of interpreting that language (more about that in a bit), but nonetheless the commonality is all that s needed to ensure comprehension. Web Services often employ the use of something called SOAP as that common language. Here s the formalized definition of SOAP, as stated within the SOAP 1.2 specification (http://www.w3.org/TR/SOAP12-part1/): SOAP is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. It uses XML technologies to define an extensible messaging framework providing a message construct that can be exchanged over a variety of underlying protocols. The framework has been designed to be independent of any particular programming model and other implementation specific semantics.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

490 CHAPTER 20 WEB SERVICES The Sun

Sunday, December 2nd, 2007

490 CHAPTER 20 WEB SERVICES Ernest Hemingway The masterpiece that launched Hemingway’s career. Jake Barnes Lady Brett Ashley Robert Cohn Mike Campbell Using the children() method, you can easily retrieve the characters: book[2]->cast->children() AS $character) { echo “$character
“; } ?> This example returns: Jake Barnes Lady Brett Ashley Robert Cohn Mike Campbell xpath() array simplexml_element->xpath (string path) XPath is a W3C standard that offers an intuitive, path-based syntax for identifying XML nodes. For example, referring to the books.xml document, you could retrieve all author nodes using the expression /library/book/author. XPath also offers a set of functions for selectively retrieving nodes based on value. Suppose you want to retrieve all authors found in the books.xml document: xpath(”/library/book/author”); foreach($authors AS $author) { echo “$author
“; } ?> This example returns:
Check Tomcat Web Hosting services for best quality webspace to host your web application.