PHP 5 soap request with XML-string param.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Grand Admiral

    PHP 5 soap request with XML-string param.

    Question.

    I have a wsdl soap request structure as follows:

    <soap:Envelop e xmlns:xsi="..." xmlns:xsd="..." xmlns:soap="... ">
    <soap:Header>.. . </soap:Header>
    <soap:Body>
    <SaveItem xmlns="...">
    <ItemXml>xml</ItemXml>
    <PropertyView>s tring</PropertyView>
    </SaveItem>
    </soap:Body>
    </soap:Envelope>

    I cant seem to work out how to add an string representation of an xml
    document as the ItemXml parameter.
    Currently I use the __soapCall() function with an assoc array as the
    second argument as shown below:

    $params = array("ItemXml" => $itemxml, "PropertyVi ew" =>
    $propertyview);
    $result = $this->soapclient->__soapCall($fu nction,
    array("paramete rs"=>$params) , null, $this->soapheaders) ;

    There is a valid XML string as the ItemXML param, however, using the
    __getLastRespon se() function I get an empty XML string as the ItemXML
    param. eg.

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." xmlns:ns1="..." >
    <SOAP-ENV:Header></SOAP-ENV:Header>
    <SOAP-ENV:Body>
    <ns1:SaveItem >
    <ns1:ItemXml />
    <ns1:PropertyVi ew>website<ns1: PropertyView>
    </ns1:SaveItem>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    Thankyou in advance for any response

    Ryan.

  • The Grand Admiral

    #2
    Re: PHP 5 soap request with XML-string param.

    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_te xt, 147);

    $params = array("ItemXml" => $soapvar, "PropertyVi ew" => "blah");
    $result = $this->soapclient->__soapCall("Sa veItem",
    array("paramete rs"=>$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:PropertyVi ew>blah</ns1:PropertyVie w>
    </ns1:SaveItem>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    Comment

    Working...