PHP SOAP客户端到WCF


PHP SOAP client To WCF

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

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

根据我使用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。我讨厌SOAP

最后,这是正确的方法:

$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的帮助!