Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

escapeOutput and webmethod

12 views
Skip to first unread message

sd

unread,
Dec 21, 2003, 10:59:40 PM12/21/03
to
Hello All,
I aplogize if this has already been answered however I
couldn't find anything related to this...

I have bunch of webservices written in vb.net returning
native data types, due to constraints of the client I need
to return data that has been output escaped i.e. when a
string response is returned back by the service it
automatically converts & to amp; and the other reserved
chracters, in this case I don't want the conversion to
happen.


Thanks
sd

Christoph Schittko [MVP]

unread,
Dec 22, 2003, 12:27:30 AM12/22/03
to

I am not quite sure I'm following. It appears you skipped a sentence or so.

In genereal though, you always want the escaping to happen, otherwise you'd
have invalid Xml! Characters like the anglebrackets ARE ONLY ALLOWED in
elements, nowhere else unless you embed them in a CDATA section.

Is that what you are looking for?

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"sd" <anon...@discussions.microsoft.com> wrote in message
news:033e01c3c840$06405f50$a301...@phx.gbl...

anon...@discussions.microsoft.com

unread,
Dec 22, 2003, 8:05:18 AM12/22/03
to
Thx! for the reply. I agree that the reserved characters
must be output escaped, however if the webmethod were to
return a string, how would I specify that its CDATA.
e.g.
<webmethod....>
public function showString( byval var as string) as string
return var
end function

now if var contains any of the special characters, they
are already xml escaped for you, I don't want that to be
xml escaped instead I would want to put that in CDATA.


Thanks
sd

>.
>

Christoph Schittko [MVP]

unread,
Dec 24, 2003, 6:18:49 PM12/24/03
to
Sd,

If you want the CDATA section directly inside the response node like this:

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetCdataResponse xmlns="http://tempuri.org/"><![CDATA[This contains
<markup> & some other gunk </markup>]]></GetCdataResponse>
</soap:Body>
</soap:Envelope>

you could define your WebMethod like this:

[WebMethod()]
[return: XmlAnyElement()]
public XmlCDataSection GetCdata()
{
XmlCDataSection cdata = new XmlDocument().CreateNode( XmlNodeType.CDATA,
"MyCDataNode", "" ) as XmlCDataSection;
cdata.Data = "POST ONLY This contains <markup> & some other gunk
</markup>";
return cdata;
}

Note that you can't test this from the browser, you'll have to use a tool
like Web Services Studio [0] to check the actual method response. The
browser submits the Request via am HTTP GET request which causes ASP.NET to
omit the <Envelope> and <Body> tags, which then in turn results in the
attempt to start a CDATA node as the first node in an Xml document, which
results in an exception.

Web Services Studio will submit the request via an HTTP POST, just like a
web services proxy generated by Visual Studio .NET and you can verify that
the response.


--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

[0]
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=65a1d4ea-0f7a-41bd-8494-e916ebc4159c

<anon...@discussions.microsoft.com> wrote in message
news:037001c3c88c$3f8f04e0$a001...@phx.gbl...

0 new messages