我正在尝试使用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.
你能告诉我吗?
答案 0 :(得分: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);
答案 1 :(得分:0)
创建一个CreateProfile的新类实例:
$createProfile = new CreateProfile();
为其分配变量:
$createProfile->firstname = 'Fred';
$createProfile->email = 'test@example.com';
...
...
然后将该对象传递给您的方法:
$client = new Profile_WebService();
$client->CreateProfile($createProfile);
答案 2 :(得分:0)
您告诉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'));