Reputation: 509
I am calling JAVA based soap services using WS security. but whenever I try to call these services they give an error of having invalid security headers. Can anyone please tell me how can I build security headers and build a Soap request using php zend framework.
Upvotes: 0
Views: 2828
Reputation: 2970
It would be helpful if you could post the code that you have sofar, to try to troubleshoot for you. Otherwise, here is an example without having any of your code.
We use the Zend Framework as well, and had the requirement to pass security headers through to an HTTPS service. The Zend Framework SOAP security headers are quite under developed IMO, we found the base PHP CURL worked much better and also easy to implement.
Within the Authorization: Basic (below) , you will notice the base64_encode... this is where we pass our userID : password.
function makeRequest($requestData){
$str = "site_id=62621&service_name=TestService&fx_request=" . $reqeustData;
$strLength = strlen($str);
$headers = array(
"Authorization: Basic " . base64_encode("12321:123456123456321654"),
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: $strLength",
);
$url = 'https://siteName.Here.com/WebServices/AccountingService';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 80);
curl_setopt($ch, CURLOPT_TIMEOUT, 80);
$response = curl_exec($ch);
if (curl_errno($ch)) {
return "Error: " . curl_error($ch);
} else {
curl_close($ch);
return $response;
}
}
Hope this helps.
--Edit to previous answer, RE comment for WSDL with WSSE security--
For WSSE security then, there is this Zend Framework class
class Zend_Service_DeveloperGarden_Client_Soap extends Zend_Soap_Client
Which has this function, which I believe is what you're looking for
addWsseSecurityTokenHeader
Please see this link for detailed description Class Description on Zend Framework website
And please see this link to view the actual codefile Code File on Zend Framework website
Upvotes: 1