PHP SOAP客户端到WCF

时间:2012-07-10 17:55:36

标签: php zend-framework soap

我需要在我的Zend应用程序中开发一个SOAP客户端,但我真的很困惑如何让它工作。我几乎尝试了任何可能的事情,用谷歌搜索了一下bilion时间,没办法让那个该死的网络服务电话工作。

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

2 个答案:

答案 0 :(得分: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。我讨厌SOAP

答案 1 :(得分: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的帮助!