Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

(SQL Anywhere 12)

I have a web service that returns part of the response as a String inside the XML, I want this also to “be” a XML, to be able to remove [CDATA[ and /DATA

How it looks today:

    < SOAP-ENV:Body >
      < tns:GetResponse >
         < tns:GetResult xsi:type="tns:SimpleDataset" >
            < tns:rowset >
               < tns:row >
               < tns:response >

< ![CDATA[< MyData >< column1 >123< /column1 >< column2 >147< /column2 >< column3 >248< /column3 > < /MyData > < /DATA >]]

< /tns:response >
               < /tns:row >
             < /tns:rowset >
          < /tns:GetResult >
         < tns:sqlcode >0< /tns:sqlcode >
       < /tns:GetResponse >
    < /SOAP-ENV:Body >

So what I want is something like this:

   < SOAP-ENV:Body >
      < tns:GetResponse >
         < tns:GetResult xsi:type="tns:SimpleDataset" >
            < tns:rowset >
               < tns:row >
               < tns:response >

< tns:MyData >
                    < tns:column1 >123
                    < tns:column2 >147
                    < tns:column3>248
                 < /tns:MyData >

< /tns:response >
              < /tns:row >
            < /tns:rowset >
         < /tns:GetResult >
       < tns:sqlcode >0< /tns:sqlcode >
     < /tns:GetResponse >
   < /SOAP-ENV:Body >

The web service

CREATE SERVICE "MyName/GetMyData" TYPE 'SOAP' AUTHORIZATION OFF USER "DBA" AS select GetMyData(:column1,:column2,:column3) as response;

Can this be done or am I stuck with [ CDATA [ and / DATA in my SOAP XML?

I have tried different FORMAT 'XML' and 'CONCRETE' when creating the webservice, but it srill returns a string

would be very happy if someone could point me in the right direction

asked 11 Nov '13, 09:30

M%20G's gravatar image

M G
629253044
accept rate: 42%

edited 11 Nov '13, 11:51

Mark%20Culp's gravatar image

Mark Culp
24.9k10141297


Well I got the solution now....

Just the ordinary procedure with a select without any XML functions at all or any cast

CREATE PROCEDURE GetMyData( @column1 integer, @column2 integer, @column3 integer ) 
BEGIN SELECT * FROM xtable
 WHERE column1 = @column1 and column2 = @column2 and column3 = @column3 
END

Your procedure should NOT return any XML code at all

In creating the service the format must be set to 'CONCRETE'

CREATE SERVICE "MyName/GetMyData" TYPE 'SOAP' AUTHORIZATION OFF USER "DBA" FORMAT 'CONCRETE' AS call GetMyData(:column1,:column2,:column3;

the columns in the select list in your procedure will be presented as element in the (SOAP) XML

(ofcourse your wsdl must also describe the result out from the webservice correct, forgot to write that in my previous comment)

permanent link

answered 15 Nov '13, 07:24

M%20G's gravatar image

M G
629253044
accept rate: 42%

edited 15 Nov '13, 07:25

What is the definition of your GetMyData procedure? function?

My guess is that your procedure is return varchar instead of XML! When the result data type is not XML then the server will automatically do what is necessary to fit into the SOAP envelope and this means munging the data so that an XML parse can properly parse it.

If you are already generating XML but returning it as char/varchar type (as I suspect) then change your procedure to describe the result (or return) type to be XML. Note you will most likely also need to change your procedure to actually produce XML ... which means that you will need to generate XML directly or cast your varchar data to XML (e.g. cast( mydata as XML )).

You may also want to use the XMLELEMENT, XMLCONCAT, and related XML functions.

permanent link

answered 11 Nov '13, 11:47

Mark%20Culp's gravatar image

Mark Culp
24.9k10141297
accept rate: 41%

Thank you for your answer,

I use a function to retrieve the data needed, but I can not see anything wrong with the function, To me it looks like it is returning a XML!

I did get another response when the webservice was created with

CREATE SERVICE "MyName/GetMyData" TYPE 'SOAP' AUTHORIZATION OFF USER "DBA" FORMAT 'XML' AS select GetMyData(:column1,:column2,:column3) as response;

Then < tns:rowset > and < tns:row > was also included in the string, that's why I thought I did something wrong creating the webservice

This is how the function looks like:

CREATE FUNCTION GetMyData( @column1 integer, @column2 integer, @column3 integer )
RETURNS XML
DETERMINISTIC
BEGIN
   DECLARE return_value XML; 
   SET return_value = CAST((SELECT * FROM xtable WHERE column1 = @column1 and column2 = @column2 and column3 = @column3 FOR XML AUTO, ELEMENTS) as XML);
   RETURN return_value;
END
(12 Nov '13, 03:22) M G

I still have not found a solution and if anyone can see what is wrong, I would be grateful if you could point it out

(12 Nov '13, 15:49) M G
Replies hidden

Could you give an example of the return value from your stored function?

(I'd think it looks OK and follows Mark's suggestion, so I don't have a clue why it is put inside a CDATA section.)

(13 Nov '13, 04:52) Volker Barth

The answer from my function is

< MyData >< column1 >123< /column1 >< column2 >147< /column2 >< column3 >248< /column3 > < /MyData >

I have experimented with using a procedure instead, but that does not help, different values on 'format' (in the creation of the web service) and using different xml functions in my procedure/function hoping that it would not result in a CDATA section but no success, I can see a difference in the result, but the result itself is always included in a CDATA section...

but the weird part is that after have made it into a procedure and just leave it like this (without any xml)

CREATE PROCEDURE GetMyData( @column1 integer, @column2 integer, @column3 integer ) BEGIN SELECT * FROM xtable WHERE column1 = @column1 and column2 = @column2 and column3 = @column3 END

CREATE SERVICE "MyName/GetMyData" TYPE 'SOAP' AUTHORIZATION OFF USER "DBA" FORMAT 'XML' AS call GetMyData(:column1,:column2,:column3;

I get the same result as I wrote before, so the cast or FOR XML does not make a difference..

Or is there any other type of setting you should also change? Is there anywhere else you should define that the answer out from the webservice should be viewed as an XML?

(14 Nov '13, 04:29) M G
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×66
×29
×19

question asked: 11 Nov '13, 09:30

question was seen: 5,865 times

last updated: 15 Nov '13, 07:25