Hi all,
I am trying to develop client server web service using soap wsdl but my code giving proper out put where input given is correct.If any body can fix this? My code attached herewith...and I got the code from the link
https://tommorrisblog.wordpress.com/2015/02/07/soap-wsdl-examples-with-php-and-python-scripting/
client.php
<?php
require_once "lib/nusoap.php";
//$client = new nusoap_client('http://localhost/SoapWebService/Today/postcodes.wsdl?WSDL', 'wsdl',$proxyhost, $proxyport, $proxyusername, $proxypassword);
$client = new nusoap_client('http://localhost/SoapWebService/Hi/postcodes.wsdl');
$client->soap_defencoding = 'UTF-8';
$param = array('country' => '198001','district' => 'AB1 0AA');
$result = $client->call('getWardsFunctionRequest', array('parameters' => $param));
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
postcode_obj.php
<?php
// filename postcodes_obj.php
class PostcodeObject { //container for a single record to be returned
public $numPostcodes;
public $wardName;
}
function getWardsFunction($wardInfo) {
$username = "pi"; //database connection credentials
$password = "raspberry";
$hostname = "localhost";
$logfile = "/tmp/postcodes.txt";
$country = $wardInfo->inputElement->country; //read inputs from client request
$district = $wardInfo->inputElement->district;
$dbhandle = mysql_connect($hostname, $username, $password); //connect to the database
//build query string (column aliases aligned with return elements)
$query = "select count(*) as numPostcodes, ward as wardName
from testdb.postcodes
where country = '" . $country . "' and district = '" . $district .
"' group by ward order by numPostcodes;";
$ret = array(); // array to be returned
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) { // populate return array with a PostcodeObject per record
$responseRecord = new PostcodeObject; // create new object
$responseRecord -> numPostcodes = $row['numPostcodes'];
$responseRecord -> wardName = $row['wardName'];
$ret[] = $responseRecord; // add object record to array
}
return $ret; # return array of objects
}
$classmap = array ('PostcodeObject' => 'wardsResponseRecord');
ini_set("soap.wsdl_cache_enabled",0);
$server = new SoapServer ( "/var/www/postcodes.wsdl", array('classmap'=>$classmap) );
$server->addFunction ( "getWardsFunction" );
$server->handle ();
?>
postcodes.wsdl
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://localhost/SoapWebService/Hi/postcodes/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="postcodes"
targetNamespace="http://localhost/SoapWebService/Hi/postcodes/"> <!-- filename postcodes.wsdl --> <wsdl:types> <xsd:schema targetNamespace="http://localhost/SoapWebService/Hi/postcodes/"> <xsd:include schemaLocation="postcodes.xsd" /> </xsd:schema> </wsdl:types> <wsdl:message name="getWardsFunctionRequest"> <wsdl:part element="tns:getWardsFunction" name="inputMessage" /> </wsdl:message> <wsdl:message name="getWardsFunctionResponse"> <wsdl:part element="tns:getWardsFunctionResponse" name="outputMessage" /> </wsdl:message> <wsdl:portType name="postcodePort"> <wsdl:operation name="getWardsFunction"> <wsdl:input message="tns:getWardsFunctionRequest" /> <wsdl:output message="tns:getWardsFunctionResponse" /> </wsdl:operation> </wsdl:portType> <wsdl:binding name="postcodesBinding" type="tns:postcodePort"> <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="getWardsFunction"> <soap:operation soapAction="http://localhost/SoapWebService/Hi/postcodes/getWardsFunction" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="postcodesService"> <wsdl:port binding="tns:postcodesBinding" name="postcodesSOAPport"> <soap:address location="http://localhost/SoapWebService/Hi/postcodes.php" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
postcodes.xsd
<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/postcodes/" xmlns:tns="http://www.example.org/postcodes/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <!-- filename postcodes.xsd --> <xsd:element name="getWardsFunction"> <xsd:complexType> <xsd:sequence> <xsd:element name="inputElement" type="tns:wardsInputRecord" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="getWardsFunctionResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="outputElement" type="tns:wardsResponseRecord" minOccurs="0" maxOccurs="unbounded"></xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:complexType name="wardsInputRecord"> <xsd:sequence> <xsd:element name="country" type="xsd:string"></xsd:element> <xsd:element name="district" type="xsd:string"></xsd:element> </xsd:sequence> </xsd:complexType> <xsd:complexType name="wardsResponseRecord"> <xsd:sequence> <xsd:element name="numPostcodes" type="xsd:int"></xsd:element> <xsd:element name="wardName" type="xsd:string"></xsd:element> </xsd:sequence> </xsd:complexType> </schema>
Thank in advance,
SUBRATA