Reputation: 1242
I have a two fold problem with setting SOAP headers. Primarily, I've never done it before and two, I can't seem to find a good solution on here for doing so. I apologize if there are exact duplicates, and please point me in the right direction if there are.
I need to set the following xmlns:xsi and xmlns:xsd data sets on the soap:Envelope. I also need to set an xmlns attribute on the first tag in the XML (rough example).
The first part needs to be added, the second part is already in there when I do a __getLastRequest(). And the third part needs to be added (just the SendPurchases xmlns attribute).
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
xmlns:ns1="urn:[taken out for security purposes]">
<soap:Body>
<SendPurchases xmlns="urn:...">
</SendPurchases>
</soap:Body>
Would I need to use the header() for this? I am using PHP's SOAP client. Any help at all is greatly appreciated!
EDIT:
I went with another route, thank you for all your answers though!
Upvotes: 2
Views: 11146
Reputation: 11700
I had a simular problem with the envelope, I made a fix for that. I will post the fix with the data you provided, You will have to check if everything is oke:
The custom class to edit the request:
class CustomSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version) {
$request = str_replace('<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">', '', $request);
// parent call
return parent::__doRequest($request, $location, $action, $version);
}
}
Setup the soap client:
$client = new CustomSoapClient($wsdl,
array(
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'exceptions' => true,
'trace' => 1,
'soap_version' => SOAP_1_2,
)
);
The request:
//notice that the envelope is in the request! also you need to change the urn
$request = '
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/xmlns:ns1="urn:[taken out for security purposes]">
<soap:Body>
<SendPurchases xmlns="urn:...">
</SendPurchases>
</soap:Body>
</SOAP-ENV:Envelope>';
$xmlvar = new SoapVar($request, XSD_ANYXML);
$result = $client->Controleer($xmlvar);
print_r($result); // finally check the result
I hope this will help you :)
Upvotes: 4
Reputation: 4142
A verbose example of the correct implementation using PHP's SoapClient can be found here: http://www.php.net/manual/en/soapclient.soapclient.php#97273
Upvotes: 1