Unable to Serialize Result

Help
2009-02-25
2013-06-06
  • Mitch Walker
    Mitch Walker
    2009-02-25

    I've put together the following server script.  The idea here is to take a zipcode as input and return the associated data from my database.  "CityStateByZip" and "LatLongByZip" both work just fine, but I've run into a roadblock with "DistZip1Zip2".  The function isn't complete yet, but at this point it should return the Latitude and Longitude for both zipcodes provided to the webservice (I intend to add the math later).  The problem is I get nothing but "Unable to Serialize Result" back in the fault message.  I've got to be missing something obvious, but I can't spot the problem.  If someone could take a look at the code and point me in the right direction I sure would appreciate it.  My Server.php follows:

    ************************* Server.php ******************************
    <?php
      // includes nusoap classes
      require('nusoap.php');
     
      // create server
      $l_oServer = new soap_server();
     
      // wsdl generation
      $l_oServer->debug_flag = false;
      $ns = "http://www.my.org/webservice";
      $l_oServer->configureWSDL('zipcodes', $ns);
      $l_oServer->wsdl->schemaTargetNamespace = $ns;
     
      $dbserver = "XXXXX";
      $db = "XXXXX";
      $dbuser = "XXXXX";
      $dbpassword = "XXXXX";
     
      // add complex type-01
      $l_oServer->wsdl->addComplexType('CityStateByZip', 'complexType', 'struct', 'all', '', array('zipcode' => array('name' => 'zipcode', 'type' => 'xsd:string'), 'cityname' => array('name' => 'cityname', 'type' => 'xsd:string'), 'statename' => array('name' => 'statename', 'type' => 'xsd:string')));
     
      // add complex type-02
      $l_oServer->wsdl->addComplexType('LatLongByZip', 'complexType', 'struct', 'all', '', array('zipcode' => array('name' => 'zipcode', 'type' => 'xsd:string'), 'latitude' => array('name' => 'latitude', 'type' => 'xsd:string'), 'longitude' => array('name' => 'longitude', 'type' => 'xsd:string')));
     
      // add complex type-03
      $l_oServer->wsdl->addComplexType('DistZip1Zip2', 'complexType', 'struct', 'all', '', array('zipcode' => array('name' => 'zipcode', 'type' => 'xsd:string'), 'latitude' => array('name' => 'latitude', 'type' => 'xsd:string'), 'longitude' => array('name' => 'longitude', 'type' => 'xsd:string')));
     
      // add complex type-03A
      $l_oServer->wsdl->addComplexType('DistZip1Zip2Array', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:DistZip1Zip2[]')), 'tns:DistZip1Zip2');
     
      // register method-01
      $l_oServer->register('getCityStateByZip', array('zipcode' => 'xsd:int'), array('return' => 'tns:CityStateByZip'), $ns);
     
      // register method-02
      $l_oServer->register('getLatLongByZip', array('zipcode' => 'xsd:int'), array('return' => 'tns:LatLongByZip'), $ns);
     
      // register method-03
      $l_oServer->register('getDistZip1Zip2', array('zipcode1' => 'xsd:int', 'zipcode2' => 'xsd:int'), array('return' => 'tns:DistZip1Zip2Array'), $ns, $ns . '#gdtDistZip1Zip2', 'rpc', 'encoded', 'Get ZipCode info');
     
      // method-01 code (get DB result)
      function getCityStateByZip($a_stInput)
      {
          if (is_int($a_stInput) && strlen($a_stInput) == 5) {
              global $dbserver, $db, $dbuser, $dbpassword;
              $l_oDBlink = @mysql_connect($dbserver, $dbuser, $dbpassword);
              $l_oDBresult = @mysql_db_query($db, 'SELECT zipcode, cityname, statename FROM zipcodes WHERE citytype = "D" and zipcode = "' . $a_stInput . '" ');
             
              // simple error checking
              if (!$l_oDBresult) {
                  return new soap_fault('Server', '', 'Internal server error.');
              }
             
              // no data avaible for x city
              if (!mysql_num_rows($l_oDBresult)) {
                  return new soap_fault('Server', '', 'Service contains no data.');
              }
             
              mysql_close($l_oDBlink);
             
              // return data
              return mysql_fetch_array($l_oDBresult, MYSQL_ASSOC);
          }
         
          // we accept only a string
          else {
              return new soap_fault('Client', '', 'ZipCode Service requires an 5 digit integer.');
          }
      }
     
      // method-02 code (get DB result)
      function getLatLongByZip($a_stInput)
      {
          if (is_int($a_stInput) && strlen($a_stInput) == 5) {
              global $dbserver, $db, $dbuser, $dbpassword;
              $l_oDBlink = @mysql_connect($dbserver, $dbuser, $dbpassword);
              $l_oDBresult = @mysql_db_query($db, 'SELECT zipcode, latitude, longitude FROM zipcodes WHERE citytype = "D" and zipcode = "' . $a_stInput . '" ');
             
              // simple error checking
              if (!$l_oDBresult) {
                  return new soap_fault('Server', '', 'Internal server error.');
              }
             
              // no data avaible for x city
              if (!mysql_num_rows($l_oDBresult)) {
                  return new soap_fault('Server', '', 'Service contains no data.');
              }
             
              mysql_close($l_oDBlink);
             
              // return data
              return mysql_fetch_array($l_oDBresult, MYSQL_ASSOC);
          }
         
          // we accept only an integer
          else {
              return new soap_fault('Client', '', 'ZipCode Service requires an 5 digit integer.');
          }
      }
     
      // method-03 code (get DB result)
      function getDistZip1Zip2($a_stInput1, $a_stInput2)
      {
          if ((is_int($a_stInput1) && strlen($a_stInput1) == 5) && (is_int($a_stInput2) && strlen($a_stInput2) == 5)) {
              global $dbserver, $db, $dbuser, $dbpassword;
              $l_oDBlink = @mysql_connect($dbserver, $dbuser, $dbpassword);
              $l_oDBresult = @mysql_db_query($db, 'SELECT zipcode, latitude, longitude FROM zipcodes WHERE citytype = "D" and zipcode = "' . $a_stInput1 . '" or zipcode = "' . $a_stInput2 . '" ');
             
              // simple error checking
              if (!$l_oDBresult) {
                  return new soap_fault('Server', '', 'Internal server error.');
              }
             
              // no data avaible for x city
              if (!mysql_num_rows($l_oDBresult)) {
                  return new soap_fault('Server', '', 'Service contains no data.');
              }
             
              mysql_close($l_oDBlink);
             
              // return data
              return mysql_fetch_array($l_oDBresult, MYSQL_ASSOC);
          }
         
          // we accept only integers
          else {
              return new soap_fault('Client', '', 'ZipCode distance service requires 2 5-digit integers.');
          }
      }
     
      // pass incoming (posted) data
      $l_oServer->service($HTTP_RAW_POST_DATA);
    ?>

     
  • Ettienne
    Ettienne
    2012-08-22

    I'm sitting with the exact same problem if anyone can answer this please.