I am trying to login to my magento's web services from a server that does not have SoapClient enabled. So I figured I would install and use Pear's SOAP_Client but I can't figure out 开发者_运维百科how to login.
With SoapClient I use:
$client = new SoapClient($WSDL);
$session = $client->login($user, $api_key);
$response = $client->call($session, $method, $arguments);
But I can't find an analog to the login
method for SOAP_Client
I gather that I should be setting something in the $proxy_params of the constructor, but I can't find what the indexes should be.
$proxy_params = array();
$client = new SOAP_Client($wsdl, true, false, $proxy_params);
$client->call($method, $arguments)
So I figured this out, and there are a couple of factors here.
There isn't a login function for SoapClient, the login I was calling is a call as defined in the WSDL
The various magento API methods are not defined in the WSDL, you provide an argument resource method to method defined as
call
by the WSDL. This created a bit of confusion because using$client->call()
seems to invokecall
as defined by the SOAP_Client class, so I need to use$client->call('call')
to invoke the SOAP methodcall
The final code ended up being:
$method = 'catalog_product.info';
$args = array($product_id);
$client = new SOAP_Client($wsdl, true);
$session_id = $client->call(
'login',
array(
'username'=>$username,
'apiKey'=> $pasword
)
);
$ret = $client->call(
'call',
array(
'sessionId'=>$session_id,
'resourcePath'=>$method,
'args'=>$args
)
);
精彩评论