Introduction to Web services with PHP5 SOAP
Is both Google's service and PEAR's SOAP are technically still in beta so there is a strange case from the time the bug occurs. There are other NuSOAP PHP5 SOAP extension and including the SOAP client libraries available, he added, is the same as that presented here is different as the basic theory of implementation details.
Setting up the PEAR SOAP module
Before we can start using SOAP, we had better make sure both PEAR itself and the SOAP module are available. The PEAR package manager is installed by default with PHP 4.3.0 and later, but if you are using an earlier version or it is missing on your system check out the PEAR manual for instructions.
Once you have the package manager installed, you will need to download the SOAP package. On most systems, you can just enter pear install SOAP into a console window. At least, thats the theory. Unless there is a stable release of SOAP available, you will get the message No release with state equal to stable found for SOAP. Try pear install SOAP beta to get the most current version of the package at the time of writing, even though it is in beta, or tell PEAR to accept beta versions without complaint by typing pear config set preferred state beta.
Perhaps you have one or more entries starting with packet calls, followed by failed dependencies. In this case, try the pear install command again to attach, but the dependencies on the command line. For example, if PEAR complains that the Net-DIME package is missing, try pear install SOAP DIME Net instead.
Getting a license key
Once, SOAP After installing the extension, the next step, Google Web API license key to get register and download the development kits. This key SOAP Day 1000 year to the query can be free. Visit http www.google.co.uk API Google Web API, follow the instructions on the next site.
Unzip the developers kit and put it in a convenient place. It only contains samples for accessing the service with .NET and Java, but most of the documentation applies equally to calling Google from PHP.
Decoding the WSDL file
In the developers kit main directory you will find a WSDL file called GoogleSearch.wsdl, which you can open in a text editor or XML browser. This file defines exactly what services we can call using SOAP, though the Google documentation is probably easier to read.
However, we can also see what the SOAP module makes of this file. Create a new PHP page and enter the following.
require once SOAP Client.php
wsdl new SOAP WSDL GoogleSearch.wsdl.
header Content Type text plain
echowsdl generateProxyCode.
Place it somewhere on your server along with GoogleSearch.wsdl and access it through your web browser. Assuming everything is working right, you should get a lot of PHP code output. This code is the result of the SOAP WSDL client class parsing the WSDL file and converting it into PHP functions. This tells us what functions we can call in a rather more readable form than the WSDL document, and is handy particularly if you are using a poorly documented WSDL service.
So how does the code work Let s go through it step by step.
1. First, we load the SOAP client file. If this gives an error, it probably means SOAP isnt installed properly and you should read the instructions above or the PEAR manual.
2. We then create an instance of the SOAP WSDL class, based on the GoogleSearch.wsdl file. This is one of the main classes we are going to use throughout this tutorial it parses the WSDL file and represents it as PHP.
3. Finally, we output the proxy code as plain text. As you can see from the output, in SOAP the proxy is a class that represents the WSDL calls available as PHP functions.
Spell checking with Google
If you have some time to talk about the use of unstable, like me, Google, you may have noticed you mean OK, if misspell a word appears in the search. On the Google network services, so we can add the spell check our PHP applications, but to be honest, it is likely to be better used in practical applications pspell. Enter the following code, you have a string as the first license key.
Simple, ISN t following the first two rows and are simple, the same as the previous example. The fourth line is an object based on a previous look at the code, by calling the method, SOAP can create a proxy request. Finally, we call the doSpellingSuggestion output the results. Web browser access to this page, please refer to your own words in a dictionary.
You may see the object, but in this case SOAP has encountered a problem, the object returned SOAP errors. We will look to deal with these failures in the future some time, but now check whether you entered the correct license key, rather than trying to exhaust your daily 1,000 query limit.
