Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sending XML in cdata via WSDL generated Service Consumer

ChRa
Explorer
0 Kudos

Hi experts,

I generated an Service Consumer via WSLD.

There is only one Function with one Parameter. The Parameter is called XmlData.

i generated xml in a string variable.

now i want to send this xml

<?xml version="1.0" encoding="UTF-8"?><root>content</root>

when i do this, the proxy encodes all the xml - Tags in the message.

the same effect, when i add cdata to the string.

<![CDATA[<?xml version="1.0" encoding="UTF-8"?><root>content</root>]]

in both cases ABAP enerateres the following:

<![CDATA[<?xml version="1.0" encoding="UTF-8"?>

Can you help me?

14 REPLIES 14

ChRa
Explorer
0 Kudos

Sorry,

perhaps i did not tell all.

The final request should look like this with a full XML in CDATA

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:myp="http://mypackage">
<soapenv:Header/>
<soapenv:Body>
<myp:sendLabelData>
<myp:XmlData>
<![CDATA[<?xml version="1.0" encoding="UTF-8"?><root>content ...</root>]]>
</myp:XmlData>
</myp:sendLabelData>
</soapenv:Body>
</soapenv:Envelope>

when i add the xml to to the service i geht this result:

<X-ML_DATA><![CDATA[<?xml version="1.0" encoding="UTF-8"?>

this is the external view:

this is the internal view:

Sandra_Rossi
Active Contributor
0 Kudos

Please use the COMMENT button for comments, questions, adding details, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

Sandra_Rossi
Active Contributor
0 Kudos

I don't see any reason why it would truncate (or it's a standard bug). What tool do you use to check XmlData content?

Sandra_Rossi
Active Contributor
0 Kudos

And how do you produce the CDATA section?

ChRa
Explorer
0 Kudos

I use transaction srt_util to display the message.

when i display the message there is this the output:

<SEND_LABEL_DATA_REQUEST>
<CONTROLLER>
<PRXCTRL>
<FIELD>XML_DATA</FIELD>
<VALUE>1</VALUE>
</PRXCTRL>
</CONTROLLER>
<X-ML_DATA><![CDATA[<?xml version="1.0" encoding="UTF-8"?><root>content</root>]]</X-ML_DATA>
</SEND_LABEL_DATA_REQUEST>

this is the code to create the XML and call the Webservice.

APPEND '<![CDATA[' TO lt_str.
APPEND '<?xml version="1.0" encoding="UTF-8"?><root>' TO lt_str.
APPEND 'content' TO lt_str.
APPEND '</root>' TO lt_str.
APPEND ']]' TO lt_str.

CONCATENATE LINES OF lt_str INTO ls_request-xml_data.

TRY.
    CREATE OBJECT lo_ls.

    lo_ls->send_label_data(
      EXPORTING
        send_label_data_request  = ls_request
      IMPORTING
        send_label_data_response = ls_response
    ).

  CATCH cx_ai_system_fault INTO lo_ex_system_fault.
    lf_str = lo_ex_system_fault->if_message~get_text( ).
    WRITE / lf_str.
ENDTRY.

i could solve it using if_xml library.

But i wont do that.

ChRa
Explorer
0 Kudos

this is the "real" content

ChRa
Explorer
0 Kudos

once more

Sandra_Rossi
Active Contributor
0 Kudos

I'm pretty sure that:

  • SRT_UTIL has a display bug which truncates the display.
  • You must use ABAP type XSDANY, mark "untyped mapping". In your ABAP code, the field is of type XSTRING and you must initialize it as follows:
ls_request-xml_data = cl_abap_codepage=>convert_from(
    '<![CDATA[<?xml version="1.0" encoding="UTF-8"?><root>content</root>]]' ).

ChRa
Explorer
0 Kudos

I did, what you said:

I changed from String to anyType

Untyped Mapping is checked.

Here is the code. Only one little change: convert_to instead of convert_from

    TRY.
    ls_request-xml_data = cl_abap_codepage=>convert_to( '<![CDATA[<?xml version="1.0" encoding="UTF-8"?><root>content</root>]]' ).
  CATCH cx_root.
ENDTRY.

Now I get the following Error.

SOAP:1001 CX_XSDANY_PARSE_ERROR:XSLT Exception aufgetreten.Im ST-Program /1SAI/SAS080D3449F89B99BDF3A3 ist bei der Serialisierung ein Fehler aufgetreten..Beim Parsen eines XML-Fragmentes ist der Fehler '' aufgetreten.

when i add the XML-only it works, but the webservice is reduced to this.

<n0:XmlData>content</n0:XmlData>

Do you have any Ideas?

BR

Sandra_Rossi
Active Contributor
0 Kudos

Right, convert_to 🙂

And I forgot the terminating ">" (<![CDATA[...]]>):

    ls_request-xml_data = cl_abap_codepage=>convert_to( '<![CDATA[<?xml version="1.0" encoding="UTF-8"?><root>content</root>]]>' ).

ChRa
Explorer
0 Kudos

still the same behaviour

SOAP:1001 CX_XSDANY_PARSE_ERROR:XSLT Exception aufgetreten.Im ST-Program /1SAI/SAS080D3449F89B99BDF3A3 ist bei der Serialisierung ein Fehler aufgetreten..Beim Parsen eines XML-Fragmentes ist der Fehler '' aufgetreten.

Sandra_Rossi
Active Contributor
0 Kudos

I wonder if it's due to the name "root" that you used. It could be a special value. Could you try another name?

Sandra_Rossi
Active Contributor
0 Kudos

Forget my last comment. I don't think it's possible to force <![CDATA[ ... ]]> format. But it's possible to do something technically equivalent. See my answer.

Sandra_Rossi
Active Contributor
0 Kudos

I think what you want to achieve:

<myp:XmlData><![CDATA[<?xmlversion="1.0" encoding="UTF-8"?><root>content ...</root>]]></myp:XmlData>

cannot be done with <![CDATA[ ... ]]>

But it's 100% equivalent to:

<myp:XmlData>& lt;?xml version="1.0" encoding="UTF-8"?& gt;& lt;root& gt;content ...& lt;/root& gt;</myp:XmlData>

NB: there is a rendering bug in the forum, so I had to insert a space after & (& lt; and & gt;) which does not exist in the real world.

So, you can do it by selecting the mark "untyped mapping" (option to show it must first be activated).

Then you initialize the value with this code:

ls_request-xml_data = cl_abap_codepage=>convert_to( '<myp:XmlData><![CDATA[<?xml version="1.0"?><root>content ...</root>]]></myp:XmlData>' ).

Which should be rendered in the web service request as follows:

<myp:XmlData>& lt;?xml version="1.0" encoding="UTF-8"?& gt;& lt;root& gt;content ...& lt;/root& gt;</myp:XmlData>