2014-08-30 19 views
0

這三個調用都失敗,預計$cust將成爲Customer()的成員,但會被解釋爲字符串。如何使這些SOAP/WSDL調用在PHP 5中工作?

<?php 
require_once ("VWSAPIClient.php"); 

$client = new VWSAPIClient(); 

$level1org = 99100; // this is our test level1org 
$prog = "XYZ"; //just a string 

$cust = new Customer(); 
$cust->LEVEL1ORG = $level1org; 
$cust->CNAME = "John Doe"; 
$cust->CUSTNUM = "JDCust1"; 

try { 
    $cust = $client->CreateCustomer($prog, $cust); 
    echo "New Customer:<BR>"; 
    foreach ($cust as $key => $value) 
     if ($value != null) 
      echo " " . $key . ": " . $value . "<BR>"; 
} 
catch (exception $e) { 
    echo $e->getMessage(), " <--- Error Message 1 " . "<BR>"; 
} 

try { 
    $cust->CUSTNUM = "JDCust1"; 
    $cust->LEVEL1ORG = $level1org; 
    $result = $client->GetCustomer($cust); 
    echo $result[0]->CUSTNUM . "<BR>"; 
} 
catch (exception $e) { 
    echo $e->getMessage(), " <--- Error Message 2 " . "<BR>"; 
} 

try { 
    $cust->CUSTNUM = "JDCust1"; 
    $cust->LEVEL1ORG = $level1org; 
    $cust->CNAME = "John Doe II"; 
    $client->ModifyCustomer($cust); 
} 
catch (exception $e) { 
    echo $e->getMessage(), "<--- Error Message 3 " . "<BR>"; 
} 
?> 

這裏是「中間件」VWASPIClient.php。我相信這個問題源於參數$args,它可能包含對象或字符串。

<?php 
require_once("VWebServiceAPI.php"); 

function errorHandler($errno, $errstr, $errfile, $errline) { 
     if($errno == E_RECOVERABLE_ERROR) 
       throw new ErrorException($errstr, $errno, 0, $errfile, $errline); 
     return false; 
} 
set_error_handler("errorHandler"); 

class VWSAPIClient { 
     private $_client; 
     private $_rc; 
     private $_endpoint = "http://192.168.254.6/v/VWebServiceAPI"; 
     private $_username = "user"; 
     private $_password = "userpass"; 

     public function VWSAPIClient() { 
       $this->_client = new VWebServiceAPI($this->_endpoint."?WSDL", array('location' => $this->_endpoint, 'login' => $this->_username, 'password' => $this->_password, 'trace' => 1, 'features' => SOAP_USE_XSI_ARRAY_TYPE + SOAP_SINGLE_ELEMENT_ARRAYS)); 
       $this->_rc = new ReflectionClass("VWebServiceAPI"); 
     } 

     public function __call($method, $args) { 
       // add the sessionid placeholder 
       array_unshift($args, "NOSESSIONID"); 

       try { 
        return $this->_rc->getMethod($method)->invokeArgs($this->_client, $args); 
       } catch(ReflectionException $e) { 
          throw new Exception("No such VWSAPI operation: ".$method); 
       } 
     } 
} 
?> 

現在用於VWSAPIClient.php。

<?php 
class Customer { 
    public $CUSTNUM; // string 
    public $LEVEL1ORG; // int 
    public $CNAME; // string 
} 

/** 
* VWebServiceAPI class 
* 
*/ 
class VWebServiceAPI extends SoapClient { 

    private static $classmap = array(
            'Customer' => 'Customer', 
            ); 

    public function VWebServiceAPI($wsdl = "VWebServiceAPI?WSDL", $options = array()) { 
    foreach(self::$classmap as $key => $value) { 
     if(!isset($options['classmap'][$key])) { 
     $options['classmap'][$key] = $value; 
     } 
    } 
    parent::__construct($wsdl, $options); 
    } 

/** 
    * 
    * 
    * @param string $PROGRAMNAME 
    * @param Customer $CUSTOMER 
    * @return Customer 
    */ 
    public function CreateCustomer($PROGRAMNAME, Customer $CUSTOMER) { 
    return $this->__soapCall('CreateCustomer', array($PROGRAMNAME, $CUSTOMER),   array(
      'uri' => 'http://www.xyz-fake.org/VWebServiceAPI', 
      'soapaction' => '' 
      ) 
     ); 
    } 

    /** 
    * 
    * 
    * @param Customer $CUSTOMER 
    * @return boolean 
    */ 
    public function ModifyCustomer(Customer $CUSTOMER) { 
    return $this->__soapCall('ModifyCustomer', array($CUSTOMER),  array(
      'uri' => 'http://www.xyz-fake.org/VWebServiceAPI', 
      'soapaction' => '' 
      ) 
    ); 
    } 

    /** 
    * 
    * 
    * @param ArrayOfCustomer $CUSTOMERS 
    * @return ArrayOfCustomer 
    */ 
    public function GetCustomer(Customer $CUSTOMERS) { 
    return $this->__soapCall('GetCustomer', array($CUSTOMERS),  array(
      'uri' => 'http://www.xyz-fake.org/VWebServiceAPI', 
      'soapaction' => '' 
      ) 
    ); 
    } 

} 

?> 

回答