User login

Payload the Way You Want with PHP5 built-in SOAP

Say you want this payload:

        <ns1:base>
            <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>
            <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>
            </itemsLine>
         </ns1:base>

 

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

You can get this exact payload with the following code:

<?php
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", "http://soapinterop.org/xsd");
$var2 = new SoapVar($item2 , SOAP_ENC_OBJECT, "urn:test", "http://soapinterop.org/xsd");

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

References

PHP Web Services Blog

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

A more complex playload, stumped.

Hope someone reads this comment and posts a solution!

 

I can't seem to create the soap request i need in PHP5. I've used soapVar, SoapParam, classmapping and just can't get what I need.

What I need is very similar to the example given here, but just with simple parent tags:

 

<ns1:base>

<everything>

<itemList>

            <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>

            <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>

            </itemsLine>

<itemList>

<everything>

         </ns1:base>

 

This appears really simple and a common structure. All I seem to get from PHP5 soap is a <param> list for the the innner xml, or a struct. I am now going to try and create the XML "by hand" using simpleXML or DOMDocument, but I would rather use PHPs built in functions.

 

Have I missed something obvious?

 

thanks :)

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.