Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使这些SOAP/WSDL调用在PHP5中工作?_Php_Soap_Wsdl - Fatal编程技术网

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

如何使这些SOAP/WSDL调用在PHP5中工作?,php,soap,wsdl,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

所有这三个调用都失败,因为它们期望
$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>";
} 
?>
现在来看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-to-php生成器,比如at,您肯定不会有任何问题

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

}

?>