How to send out plain XML in SOAP response?

tok picture tok · Mar 15, 2013 · Viewed 9.1k times · Source

I'm using PHP SoapServer class and try to put plain XML inside the body of the SOAP response.

Case 1:

My WSDL has

<element name="getDataResponse" type="xsd:string"/>

I encode the response

return new SoapVar($my_xml,XSD_ANYXML)

PHP SoapClient says

SOAP-ERROR: Encoding: Violation of encoding rules

Case 2:

WSDL

<element name="getDataResponse" type="xsd:string"/>

response encoding

return new SoapVar($my_xml,XSD_STRING)

response XML has all < encoded as &lt; and > as &gt;

Case 3:

WDSL

<element name="getDataResponse">
  <complexType>
   ... 
  </complexType>
</element>

where complexType corresponds the structure of XML to return

response encoding

return new SoapVar($my_xml,XSD_ANYXML)

now return type is an object, not XML string

Case 4

same as case 3 except encoding as SOAP_ENC_OBJECT. Again result will be object.

Please help! How can I get just plain XML text as body of the SOAP response?

Answer

CL22 picture CL22 · Mar 15, 2013

Have you tried this?

return new SoapVar(
     '<ns1:xmlDocument>'.$my_xml.'</ns1:xmlDocument>',
     XSD_ANYXML
);

There are other solutions as well at this PHP page. (See 'User Contributed Notes' section)