PHP SOAP客户端到WCF
我需要在我的Zend应用程序中开发一个SOAP客户端,但是我对如何使其工作非常困惑。我尝试了几乎所有可能的方法,搜索了大约百万年的时间,并且没有办法让这个该死的web服务调用起作用。PHP SOAP客户端到WCF
客户端应该允许我流式传输图像和少量字符串,以获得证书和对象作为响应。
最后,这是做了正确的方式:
$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和塞巴斯蒂安·洛伯他们的帮助!
我与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
您好,非常感谢您的帮助,但我怎么能找到“安全”于我而言,什么我应该把安全吗? UsernameToken? – dgh 2012-07-10 22:26:46
谢谢我帮助dgh。我想我创建了一个很好的请求,但是缺少SOAPVar中的名称空间。将尝试与它 – 2012-07-11 12:26:18
如果您的问题解决了,你应该张贴一个答案和接受,而不是把它*解决*为您的标题 – j0k 2012-08-07 13:19:11