Formatting XML in Web Service Response Using HTTP POST

Discussion in 'ASP .Net Web Services' started by SimonDev, Aug 31, 2006.

  1. SimonDev

    SimonDev Guest

    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
     
    SimonDev, Aug 31, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Peleg, Creo
    Replies:
    2
    Views:
    784
    Ron Peleg, Creo
    Feb 13, 2006
  2. Replies:
    6
    Views:
    6,056
    Tor Iver Wilhelmsen
    Aug 29, 2005
  3. Brybot
    Replies:
    6
    Views:
    1,189
    John Saunders [MVP]
    Jul 9, 2007
  4. James Appleby
    Replies:
    1
    Views:
    2,581
    Donkey Hot
    Feb 6, 2008
  5. DotNetGruven

    Web Service only offers SOAP, where did HTTP-POST go?

    DotNetGruven, Jun 17, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    391
    DotNetGruven
    Jun 17, 2004
Loading...

Share This Page