如何在PHP 5中使这些SOAP / WSDL调用工作?

时间:2014-08-30 16:22:51

标签: php soap wsdl

所有这三个调用都未能期望$cust成为Customer()的成员,但会被解释为字符串。

<?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>";
} 
?>

这是&#34;中间件&#34; 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' => ''
           )
      );
  }

}

?>

1 个答案:

答案 0 :(得分:0)

开始在https://github.com/mikaelcom/WsdlToPhp使用真实的WSDL到https://www.wsdltophp.com之类的php生成器,你肯定会没有问题