I am attempting to interact with a WCF4 service using PHP SoapClient.
I have successfully created the client object and connected. I can list functions and types using ->getFunctions(), ->getTypes().
I'm trying to run one of our custom methods (SignIn), which returns an object containing 2 strings (sessionID & sitename). This method requires one parameter which is a custom object type (SignInDetails), which in turn contains 3 strings ('Sitename', 'Username', 'Password' ).
My first class is used to build the SignInDetails object containing these details. Second class runs our custom method and passes the object as a parameter however the method always responds with:
Uncaught SoapFault exception: [a:InternalServiceFault] Object reference not set to an instance of an object
class clsLoginCredentials {
public $Sitename = null;
public $Username = null;
public $Password = null;
public function __construct() {
$this->Sitename = 'test';
$this->Username = 'test';
$this->Password = 'test';
}
}
class clsloginSession {
private $client = null;
private $objLoginCredentials = null;
public function __construct() {
$this->objLoginCredentials = new clsLoginCredentials;
$this->client = getClient();
}
public function loginSessionContractData() {
return $this->client->SignIn( $this->objLoginCredentials );
}
}
$testSession = new clsloginSession;
$testSessionData = $testSession->loginSessionContractData();
var_dump( $testSessionData );
I have identified the issue. Soap expects the object to be passed in via an associated array with a key that reflects the parameter name as below:
public function loginSessionContractData() {
return $this->client->SignIn( array( 'signInDetails' => $this->objLoginCredentials ) );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.