0

我正在尝试使用 wsdl2php 在 PHP 中使用 Web 服务,但无法完成。生成的 Web 服务客户端代码和结果是:

class CreateProfile {

  public $firstname;
  public $email;
  public $lastname;
  public $mobile;
  public $password;
  public $provider;
  public $uniqueID;
  public $username;
}

class CreateProfileResponse {

  public $CreateProfileResult;
}

class Profile_WebService extends SoapClient {

  private static $classmap = array(

  'CreateProfile' => 'CreateProfile',
  'CreateProfileResponse' => 'CreateProfileResponse',
);

public function Profile_WebService($wsdl = "http://domain/wcfservice/Profile.WebService.asmx?WSDL", $options = array()) {
foreach(self::$classmap as $key => $value) {
  if(!isset($options['classmap'][$key])) {
    $options['classmap'][$key] = $value;
  }
}
parent::__construct($wsdl, $options);
}


public function CreateProfile(CreateProfile $parameters) {
  return $this->__soapCall('CreateProfile', array($parameters),       array(
          'uri' => 'http://domain/',
          'soapaction' => ''
         )
     );
  }

}

我想像这样使用它:

$client = new Profile_WebService();
$client->CreateProfile(array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));

但它一直在说:

PHP Catchable fatal error:  Argument 1 passed to Profile_WebService::CreateProfile() must be an instance of CreateProfile, array given, called.

你能启发我吗?

4

3 回答 3

1

CreateProfile需要一个对象,而不是数组。所以这:

$client = new Profile_WebService();
$client->CreateProfile(array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));

可以快速切换到这个:

$client = new Profile_WebService();
$CreateProfile_array = array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062');
$CreateProfile_object = (object)$CreateProfile_array;
$client->CreateProfile($CreateProfile_object);
于 2013-01-26T08:59:25.337 回答
0

创建一个 CreateProfile 的新类实例:

$createProfile = new CreateProfile();

为其分配变量:

$createProfile->firstname = 'Fred';
$createProfile->email = 'test@example.com';
...
...

然后将该对象传递给您的方法:

$client = new Profile_WebService();
$client->CreateProfile($createProfile);
于 2013-01-26T09:00:11.797 回答
0

您告诉 PHP 期望在CreateProfile()type 的函数 1 参数中CreateProfile

但是在这一行$client->CreateProfile(array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));中,您传递的是数组类型的变量。

您必须将该数组类型转换为 type object,如下所示:

$client->CreateProfile((object) array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));
于 2013-01-26T09:03:38.517 回答