Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / December 2003

Tip: Looking for answers? Try searching our database.

escapeOutput and webmethod

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sd - 22 Dec 2003 03:59 GMT
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] - 22 Dec 2003 05:27 GMT
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?

Signature

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

> Hello All,
>    I aplogize if this has already been answered however I
[quoted text clipped - 10 lines]
> Thanks
> sd
- 22 Dec 2003 13:05 GMT
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-----
>
[quoted text clipped - 22 lines]
>
>.
Christoph Schittko [MVP] - 24 Dec 2003 23:18 GMT
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.

Signature

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

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

> Thx! for the reply. I agree that the reserved characters
> must be output escaped, however if the webmethod were to
[quoted text clipped - 46 lines]
> >
> >.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.