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
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...
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
>.
>
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
<anon...@discussions.microsoft.com> wrote in message
news:037001c3c88c$3f8f04e0$a001...@phx.gbl...