I know very few things about XML and SOAP requests, but I am in a situation I have to consume a web service using PHP to send and receive data for my app, so any help would be appreciated.
The web service is a WSDL service, it exposes a function called processIncomingMessage()
and expects the SOAP envelope body to look like this:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<processIncomingMessageRequest xmlns="http://icis.externaldomain.services.ws">
<!-- Optional -->
<messageRequest xmlns="">
<DigitallySignedMessage>
<xmlMessage>[anyType]</xmlMessage>
</DigitallySignedMessage>
</messageRequest>
</processIncomingMessageRequest>
</Body>
</Envelope>
So when I get the form values in JSON, I proceed like this:
//convert JSON to array
$data = json_decode($json, true);
//convert array to XML
$xmlMessage = ArrayToXml::convert($data, $root);
//set the function arguments
$messageRequest = [
"messageRequest" => [
"DigitallySignedMessage" => [
"xmlMessage" => $xmlMessage,
"isXmlString" => $isXmlString,
"messageType" => $messageType
],
"traderID" => $traderID,
"wsPass" => $wsPass,
"wsUserID" => $wsUserID
]
];
//create soap client instance
$client = new SoapClient($wsdl, $soapOptions);
//call the SOAP function and save the response in a var
$response = $client->processIncomingMessage($messageRequest);
The ArrayToXml
makes use of the DOMDocument
class to create the xml and
I fount it here: https://github.com/spatie/array-to-xml/blob/master/src/ArrayToXml.php
Now, even though I validated the XML created above against the provided xsd file and on the web service's website with their own tool, the SOAP response looks like this:
status: Invalid Argument
explanation: XML Message String but class is class com.sun.org.apache.xerces.internal.dom.ElementNSImpl
I have no idea what I am doing wrong here... Could anybody shed some light?