2012-07-10 10 views
2

我需要在我的Zend應用程序中開發一個SOAP客戶端,但是我對如何使其工作非常困惑。我嘗試了幾乎所有可能的方法,搜索了大約百萬年的時間,並且沒有辦法讓這個該死的web服務調用起作用。PHP SOAP客戶端到WCF

客戶端應該允許我流式傳輸圖像和少量字符串,以獲得證書和對象作爲響應。

+0

如果您的問題解決了,你應該張貼一個答案和接受,而不是把它*解決*爲您的標題 – j0k 2012-08-07 13:19:11

回答

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和塞巴斯蒂安·洛伯他們的幫助!

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

+0

您好,非常感謝您的幫助,但我怎麼能找到「安全」於我而言,什麼我應該把安全嗎? UsernameToken? – dgh 2012-07-10 22:26:46

+0

謝謝我幫助dgh。我想我創建了一個很好的請求,但是缺少SOAPVar中的名稱空間。將嘗試與它 – 2012-07-11 12:26:18