468,268 Members | 1,511 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

escapeOutput and webmethod

sd
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
Nov 12 '05 #1
3 2471

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" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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

Nov 12 '05 #2
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
-----Original Message-----

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'dhave invalid Xml! Characters like the anglebrackets ARE ONLY ALLOWED inelements, 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" <an*******@discussions.microsoft.com> wrote in messagenews:03****************************@phx.gbl...
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

.

Nov 12 '05 #3
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/U...4-e916ebc4159c

<an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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
-----Original Message-----

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" <an*******@discussions.microsoft.com> wrote in

message
news:03****************************@phx.gbl...
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

.

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Alin Popovici | last post: by
5 posts views Thread by John | last post: by
3 posts views Thread by Khurram | last post: by
2 posts views Thread by John | last post: by
reply views Thread by anithaapr05 | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.