views:

187

answers:

1

I am trying to call a publicly available web service from a PHP web page.

The web service is: http://www.webservicex.net/uszip.asmx?WSDL


My code:

<html>
<body>
<?php
$zip = $_REQUEST['zip'];
echo 'zip is'.$zip;
?>
<form action="wszip.php" method="post">
<table cellspacing="10" bgcolor="CadetBlue">
<tr>
<td><B>Enter Zip Code : </B><input type="text" name="zip" /></td>
<td></td>
<td><input type="Submit" value="Find It!"/></td>
</tr>
</table>
<BR><BR><BR><BR>
</form>
<?php
if($zip != "")
{
    $wsdl = "http://www.webservicex.net/uszip.asmx?WSDL";
    $client = new soapclient($wsdl, true);
    $response = $client->GetInfoByZIP($zip);
}
?>
</body>
</html>
+5  A: 

You're feeding the ZIP code in incorrectly, and your constructor syntax is also incorrect. Use this syntax instead:

$wsdl = "http://www.webservicex.net/uszip.asmx?WSDL";
$client = new soapclient($wsdl);
$response = $client->GetInfoByZIP(array('USZip' => $zip));

I just tested it, and it works fine. The documentation is here.

James Skidmore
I tried the above code, still doesnt work.. just put in echo after each of the stmts and found that there is some issue with the line $client = new soapclient($wsdl);The echo that was placed after this line doesnt display. Is there any library that needs to be installed for me to create that soapclient object? if so, how can i check whether it is installed on the web server or not.Thanks
thezone
To check if you have the soap client installed, call the function phpinfo() and check for a section called "Soap" and make sure it's enabled. If it's not there, install Soap and try again: http://www.quietearth.us/articles/2006/10/10/Install-PEAR-SOAP-client-in-php
James Skidmore
Thanks.. phpinfo doesnt show a SOAP section. will check with the web admin and get back!
thezone
Sounds good. Post here what you find out.
James Skidmore