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

Hello,

You must understand that you don't ask about how to use web services in PHP but what is going wrong with the specific tutorial that you read. That means that if someone will answer will have to read that tutorial , try it see if there are any errors , fix them and then GUESS what is going wrong with your code.

You wrote “my code giving proper output ” I believe that you can understand that this is far from being the description of the problem that you are facing.

Web Services have two tiers , the server – provider and the client - consumer. Although your question has to do with the client that consumes the service If I understood correct , you created also the server that provide this service.

In bottom line , what are you trying to do exactly?

Hello,

Actually what I tried to do is:

There will be two files client.php and server.php where
client will request with the parameters say CUSTOMERID, DISTRIBUTORID,etc and based on these information server will respond say UNIT PRICE , DISCOUNT etc using WSDL . However again I studying the tutorial to rectify the code and posting shortly in this forum.

Thanks,
SUBRATA

Dear Jkon,

I wrote "my code giving proper output " what I mean to say there is no error given in output but data is not coming as response and that is what I am trying exatly.

Subrata

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.