如何使这些SOAP/WSDL调用在PHP5中工作


How can I make these SOAP/WSDL calls work in PHP 5?

这三个调用都失败,期望$custCustomer()的成员,但被解释为字符串。

<?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' => ''
           )
      );
  }
}
?>

开始使用真正的WSDL到php生成器https://github.com/mikaelcom/WsdlToPhp在https://www.wsdltophp.com并且您最终肯定不会遇到任何问题