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 < and > as >
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?
SOAP uses the XML Information Set as a message format and relies on application layer protocols, like HTTP, for message transmission and negotiation.
SOAP works with XML only The two most popular data formats are XML and JSON. XML (or Extensible Markup Language) is a text format that establishes a set of rules to structure messages as both human- and machine-readable records. But XML is verbose as it aims at creating a web document with all its formality.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With