Formatting XML in Web Service Response Using HTTP POST

S

SimonDev

Hi

I've got a problem regarding the formatting of the body of an HTTP response
from a web service.

We are using pure HTTP (POST) rather than SOAP for communicating to and from
web methods to reduce message sizes and save network charges over a cellular
network. Each web method returns an XmlDocument. Does anyone know how .NET
works under the hood to format an XmlDocument sent over pure HTTP? Is there
any way to control the formatting of an XmlDocument returned from a web
service over pure HTTP (not SOAP)?

The reason I ask is that one of the XmlDocuments returned from a web method
is being automatically formatted with leading spaces to indents elements and
carriage return-line feeds to add line breaks after each element. Ethereal
shows these formatting characters are in the HTTP response as it is
transmitted, they are not being added on the client side.

I cannot see any way of getting rid of this formatting. [BTW, all other
XmlDocuments returned from web methods are simple, a single value enclosed in
a single element. These have no problem. The problem XmlDocument is the
only one with multiple elements.]

I'm working in ASP.NET 2.0, running on IIS 6.0 on a Windows Server 2003 box.

These are the avenues I've already investigated:

1) Is Weird Formatting Being Generated by the Web Method: Nope. Debugging
the web method code I put a break point on the line that returns the
XmlDocument and copied the XmlDocument into a character array before it was
returned. The character array showed none of the carriage return - line feeds
nor the indenting spaces. So the formatting does not seem to be applied in
the web method.

2) Is Weird Formatting Being Generated by the HTTP Header of the Response:
Nope. I created a simple HTTP handler test class from scratch (not an asmx
class relying on web service attributes) and had it return a sample
XmlDocument. The XML in this response had no weird formatting problems
although the HTTP header settings were identical to the settings of the HTTP
response from the web method I'm having trouble with (in particular, both use
content-type text/xml; charset=utf-8).

3) Can the Web Method Output the XML as a String Instead of an XmlDocument:
Nope. I tried changing the return type of the web method to string and
returning the XmlDocument.OuterXML. No weird formatting problems but all the
tags were escaped (< >). Once again this adds too many extra characters to
the message.

4) Does Changing Return Type from XmlDocument to XmlNode Work: Nope.

5) Does Commenting Out the WebServiceBinding attribute on the web service
work: Nope.

I'm pretty much stumped. There seems to be virtually nothing on the
internet about web services using HTTP, it's all about SOAP. I've found no
mention anywhere of anyone with a similar problem.

I'm sure there's probably a really simple explanation, something I've
overlooked, but I'm all out of ideas.

Cheers
Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top