2

I have a JAX-WS Web-Service which accepts some basic data and a String which is supposed to contains the content of a whole XML file. In the first time I though I can just put this XML in my SOAP request as a CDATA section like this:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
    ...
      <contentData>
    <![CDATA[
      <my>
        <xml>
          <here>
            ...
          </here>
        </xml>
      </my>
    ]]>
       </contentData>
       ...
   </soapenv:Body>
</soapenv:Envelope>

But the issue is that my XML data contains as well some CDATA sections and it is not working like this as nested CDATA are not allowed (W3School reference).

What would be the best practice to send such data?

  • solution 1: escaping all special characters in order to have &lt; and &gt; (among others)
  • solution 2: convert my XML in base64 and decode it in my web-service
  • another solution welcome

I saw this question but serialising the Java object is not an option as the XML data are generated by another side.

рüффп
  • 5,172
  • 34
  • 67
  • 113

2 Answers2

1

I definitely prefer Solution 2, encoding and decoding Base64 formats.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Hemanth
  • 647
  • 7
  • 17
1

I found this answer:

Use XmlDocument as param type in the Web-Service, rather than string

This is what the Web-Service I am communicating with is using.

рüффп
  • 5,172
  • 34
  • 67
  • 113
FX Swede
  • 31
  • 3
  • That would be the best choice when you have the hand on the web-service contract (WSDL). But in my case I was using an existing service that I was not able to change. – рüффп Jun 21 '17 at 19:20
  • 2
    link is broken, can you update your answer with more details? – Ori Marko Apr 30 '19 at 06:20