How to build a correct SOAP request with PHP

“Is there a more direct approach where I could write the XML?”

By using a SoapVar and setting the encode parameter of the constructor to XSD_ANYXML you can write the raw XML.

There should be a way where the WSDL helps build the XML though.

You could try something like this:

$wsdl   = "http://api.notificationmessaging.com/NMSOAP/NotificationService?wsdl"; 
$client = new SoapClient($wsdl, array(  'soap_version' => SOAP_1_1,
                                        'trace' => true,
                                      )); 
try {

    $xml="<arg0>
            <content>
                <entry>
                    <key>1</key>
                    <value>
                    <![CDATA[
                    <table width="600">
                    <tr>
                    <td>
                    <font size="2" face="Arial">Our powerful algorithms already
                    found a matching profile that matches your criteria:
                    <br>Celina72&nbsp;</font>
                    <img src="http://mypath/to/my/image.gif" width="50"
                    height="50" border="0" />
                    </td>]]></value>
                </entry>
            </content>
            <dyn>
                <entry>
                    <key>FIRSTNAME</key>
                    <value>john</value>
                </entry>
            </dyn>
            <email>[email protected]</email>
            <encrypt>BdX7CqkmjSivyBgIcZoN4sPVLkx7FaXGiwsO</encrypt>
            <notificationId>6464</notificationId>
            <random>985A8B992601985A</random>
            <senddate>2008-12-12T00:00:00</senddate>
            <synchrotype>NOTHING</synchrotype>
            <uidkey>EMAIL</uidkey>
        </arg0>";

    $args = array(new SoapVar($xml, XSD_ANYXML));    
    $res  = $client->__soapCall('sendObject', $args);
    return $res;
} catch (SoapFault $e) {
    echo "Error: {$e}";
}

echo "<hr>Last Request";
echo "<pre>", htmlspecialchars($client->__getLastRequest()), "</pre>";

Leave a Comment