0

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?

gothaf
  • 218
  • 4
  • 14
  • Offhand it sounds like the function expects a string as the messageRequest parameter but is getting an object of some kind instead. – Wesley Smith Mar 07 '20 at 23:39
  • When I call the lastRequest I get this, ````<?xml version="1.0" encoding="UTF-8"?> <CC515A><SynIdeMES1>UNOC</SynIdeMES1><SynVerNumMES2>3</SynVerNumMES2><MesSenMES3>TRADER</MesSenMES3><MesRecMES6>NICA</MesRecMES6><DatOfPreMES9>101103</DatOfPreMES9><TimOfPreMES10>...```` so I am assuming I send a string. Right? – gothaf Mar 07 '20 at 23:44
  • Seems like $xmlMessage would be a string, but the code is passing $messageRequest to that function which seems to be an array – Wesley Smith Mar 07 '20 at 23:45
  • The $xmlMessage is the actual message I need to send... it is my form values converted to xml – gothaf Mar 07 '20 at 23:46
  • Got it, but you then put that into $messageRequest, and t that is what gets passed to processIncomingMessage. If the function expects XML, its not getting it – Wesley Smith Mar 07 '20 at 23:47
  • Do you have a link to the docs for `processIncomingMessage`? – Wesley Smith Mar 07 '20 at 23:47
  • https://www1.gsis.gr/wsicisnet/MessageProcessorService?wsdl this is it... – gothaf Mar 07 '20 at 23:49
  • Hmm, was hoping for more to go on than the wsdl. What service are you trying to use exactly? – Wesley Smith Mar 07 '20 at 23:55
  • It's a customs declaration web service... – gothaf Mar 07 '20 at 23:59
  • Hmm, see if this helps https://stackoverflow.com/a/11714489/1376624 – Wesley Smith Mar 08 '20 at 00:02
  • This WS gives me the option to pass the xmlMessage as an embedded XML structure instead of a string. Is there any chance that you know how I could accomplish that...? – gothaf Mar 08 '20 at 00:09
  • No I dont, sorry – Wesley Smith Mar 08 '20 at 00:11
  • 1
    That's ok! Thank you for taking the time to help me out... – gothaf Mar 08 '20 at 00:12

0 Answers0