Hello,

I am using php version 5.1.0.

I am attempting to execute a web service, which has the wsdl structure shown below:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="..." xmlns:xsd="..." xmlns:soap="...">
<soap:Header>...</soap:Header>
<soap:Body>
<SaveItem xmlns="...">
<ItemXml>xml</ItemXml>
<PropertyView>string</PropertyView>
</SaveItem>
</soap:Body>
</soap:Envelope>

I have an existing SoapClient object, and I have been able to successfully execute other web services. However, when I attempt the aforementioned request 'SaveItem' (with an xml param), I am having many problems.

As shown in the wsdl, the ItemXml requires xml as its content. I have tried using an domelement, domdocument, xml-string etc. but so far all have failed. When I use domelement or domdocument as the 'ItemXml' param the soapCall() function kills the execution immediately. On the other hand, when I use a string-xml representation I get a custom 'Invalid XML' message from the server, and on viewing the getLastRequest() data, it is evident that the 'ItemXml' param is null as shown below:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="..." xmlns:ns1="...">
<SOAP-ENV:Header>...</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:SaveItem>
<ns1:ItemXml/>
<ns1😛ropertyView>website</ns1😛ropertyView>
</ns1:SaveItem>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The __soapCall() function is as shown below:

$params = array("ItemXml" => $itemxml, "PropertyView" => $propertyview);
$result = $this->soapclient->__soapCall($function, array("parameters"=>$params), $options, $this->soapheaders);

I am totally unsure what to do! I have not been able to work this out 😕

    Partial solution found:

    If you want to pass an xml document node as a function parameter, your need to create a SoapVar object with a text represention of the xml node and the XSD_ANYXML encoding constant. However, this constant is not exported by the extension and is not documented for some unknown reason.

    Therefore, to get this to work you must either register the XSD_ANYXML #define as a PHP constant, or use the integer value of the constant when creating the SoapVar, which is 147.

    $soapvar = new SoapVar($xml_text, 147);

    $params = array("ItemXml" => $soapvar, "PropertyView" => "blah");
    $result = $this->soapclient->__soapCall("SaveItem", array("parameters"=>$params), null, $this->soapheaders);

    However, this still doesnt give the correct result. For some reason, the ItemXml parameter node is not wrapped around the associated xml parameter in the soap request, and the following soap is produced (assumming '<item>blah</item>' is used as the $xml_text):

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." xmlns:ns1="...">
    <SOAP-ENV:Header>...</SOAP-ENV:Header>
    <SOAP-ENV:Body>
    <ns1:SaveItem>
    <item>blah</item>
    <ns1😛ropertyView>blah</ns1😛ropertyView>
    </ns1:SaveItem>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    I have hacked a solution to manually wrap the ItemXml parameter around the parameter value itself, but I am looking for a better solution.

      Write a Reply...