我正在尝试用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.你能给我讲讲吗?
发布于 2013-01-26 17:00:12
创建一个新的CreateProfile类实例:
$createProfile = new CreateProfile();将vars分配给它:
$createProfile->firstname = 'Fred';
$createProfile->email = 'test@example.com';
...
...然后将该对象传递到您的方法中:
$client = new Profile_WebService();
$client->CreateProfile($createProfile);发布于 2013-01-26 16:59:25
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-26 17:03:39
您告诉PHP在CreateProfile类型的函数CreateProfile() 1参数中。
但是在这行$client->CreateProfile(array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));中,您传递的是一个数组类型的变量。
您必须将该数组类型转换为object类型,如下所示:
$client->CreateProfile((object) array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));https://stackoverflow.com/questions/14535353
复制相似问题