问题
I'm attempting to get values from a webservice.
The responce is formated as..
<campaign Id="200"> <name> test </name> </campaign>
PHP Code
SoapClient( "WSDL");
$return = $client->GetCampaigns('Username', 'Password' );
Yet when I attempt to access the return, I get just a stdClass with the name attribute..
public 'Campaign' =>
array
0 =>
object(stdClass)[46]
public 'Name' => string 'chris test' (length=10)
回答1:
I find that I have to supply a "classmap" to SoapClient to get it to map the objects in the response to classes that are defined in PHP. In WSDLs the type name is usually lower camel case (starting with lower case and camel case the rest).
class MY_Campaign {
private $name;
function getName () { return $this->name; }
}
$options = array(
'classmap' => array(
'campaign' => 'MY_Campaign',
);
);
$client = new SoapClient('http://example.com/yourservice?wsdl', $options);
$return = $client->GetCampaigns ();
I might be able to supply a better answer if I had the WSDL. The classmap depends on the type definitions in the WSDL file.
来源:https://stackoverflow.com/questions/3959839/php-soapclient-returning-attribute-values-in-a-response