Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send out plain XML in SOAP response?

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?

like image 922
tok Avatar asked Mar 15 '13 09:03

tok


People also ask

Which protocol can SOAP send XML on?

SOAP uses the XML Information Set as a message format and relies on application layer protocols, like HTTP, for message transmission and negotiation.

Does SOAP work with XML?

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.


1 Answers

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)

like image 92
CL22 Avatar answered Sep 21 '22 18:09

CL22