Reputation: 51
I need to develop a SOAP Client in my Zend Application but i am really confused on how to make it work. I tried almost anything possible, googled about a bilion times and no way to make that damn webservice call to work.
The Client should allow me to stream an image, and few strings, in order to get certificate and a object as response.
Upvotes: 2
Views: 1765
Reputation: 51
Finally that was the correct way to do it:
$client = new Zend_Soap_Client($myWebServiceUri,array(
'encoding' => 'UTF-8'
));
$client->setSoapVersion(SOAP_1_1);
$url = '/var/www/upload/test.jpg';
$file = fread(fopen($url, "r"), filesize($url));
function generateHeader() {
$headers[] = new SoapHeader( $ns , 'AccountName', new SoapVar( 'login', XSD_STRING, null, null, null, $ns ), false );
$headers[] = new SoapHeader( $ns , 'AccountPassword', new SoapVar( 'password', XSD_STRING, null, null, null, $ns ), false );
$headers[] = new SoapHeader( $ns , 'Agency', new SoapVar( 'agency', XSD_STRING, null, null, null, $ns ), false );
$headers[] = new SoapHeader( $ns , 'FileName', new SoapVar( 'filename', XSD_STRING, null, null, null, $ns ), false );
$headers[] = new SoapHeader( $ns , 'Options', new SoapVar( options, XSD_STRING, null, null, null, $ns ), false );
return $headers;
}
$soapHeaders = generateHeader();
$client->getSoapClient()->__setSoapHeaders( $soapHeaders );
$result = $client->ControlMRZ(array('FileStream'=>$file));
Zend_Debug::dump($result);
Thanks to @aporat and to Sebastien Lorber for their help !
Upvotes: 0
Reputation: 5932
from my experience with Zend_Soap, you need to pass the arguments as an array, for example:
$client->ControlMRZ(array('file' => $file, 'filestream' => 'test.jpg', 'anothervar' => 0);
to pass SOAP headers, you can attach SOAPHeader
objects to your soap request, as such:
/**
* Generate the auth token and create a soap header
*
* @return SoapHeader
*/
private function generateAuthHeader()
{
$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$token = new stdClass ();
$token->Username = new SOAPVar ( $this->_vendor, XSD_STRING, null, null, null, $ns );
$token->Password = new SOAPVar ( $this->_password, XSD_STRING, null, null, null, $ns );
$wsec = new stdClass ();
$wsec->UsernameToken = new SoapVar ( $token, SOAP_ENC_OBJECT, null, null, null, $ns );
$headers = array(new SOAPHeader ( $ns, 'Security', $wsec, true ));
return $headers;
}
$this->_client->getSoapClient()->__setSOAPHeaders ( $this->generateAuthHeader () );
PS. I hate SOAP
Upvotes: 2