Payload the Way You Want with PHP5 built-in SOAP

Wednesday, January 30, 2008

Say you want this payload:

            <itemsLine xsi:type="ns2:urn:test">
               <name xsi:type="xsd:string">A</name>
               <type xsi:type="xsd:string">D</type>
               <from xsi:type="xsd:string">C</from>
               <fluke xsi:type="xsd:string">D</fluke>
            <itemsLine xsi:type="ns2:urn:test">
               <name xsi:type="xsd:string">E</name>
               <type xsi:type="xsd:string">H</type>
               <from xsi:type="xsd:string">G</from>
               <fluke xsi:type="xsd:string">H</fluke>


How do you get this XML to be output by the SoapClient?

You can get this exact payload with the following code:

class itemsLine{
    function itemsLine($a, $b, $c, $d)
        $this->name = $a;
        $this->type = $d;
        $this->from = $c;
        $this->fluke = $d;

$client = new SoapClient(null, array('location' => "http://localhost:9090/soap.php",
                                     'uri'      => "http://test-uri/"));
$item1 = new itemsLine('A', 'B', 'C', 'D');
$item2 = new itemsLine('E', 'F', 'G', 'H');

$var1 = new SoapVar($item1 , SOAP_ENC_OBJECT, "urn:test", "");
$var2 = new SoapVar($item2 , SOAP_ENC_OBJECT, "urn:test", "");

$client->base(new SoapParam($var1, "itemsLine"), new SoapParam($var2, "itemsLine"));

No comments: