2

我需要在我的 Zend 应用程序中开发一个 SOAP 客户端,但我真的很困惑如何让它工作。我尝试了几乎所有可能的方法,在谷歌上搜索了十亿次,但没有办法让那个该死的网络服务调用正常工作。

客户端应该允许我流式传输图像和少量字符串,以便获取证书和对象作为响应。

4

2 回答 2

2

根据我对 Zend_Soap 的经验,您需要将参数作为数组传递,例如:

$client->ControlMRZ(array('file' => $file, 'filestream' => 'test.jpg', 'anothervar' => 0); 

要传递 SOAP 标头,您可以将SOAPHeader对象附加到您的 soap 请求,如下所示:

/**
 * 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。我讨厌肥皂

于 2012-07-10T21:02:12.480 回答
0

最后这是正确的方法:

$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);

感谢@aporat 和 Sebastien Lorber 的帮助!

于 2012-07-11T20:20:43.133 回答