Alan
Alan

Reputation:

Delphi 2009 Web Services "xml document must have a top level element"

A variety of delphi demos I've built today with Delphi 2009 (update 3/4 applied) all seem to result in the client of any localhost web service I try to consume returning an "xml document must have a top level element" error

This includes, for example, even a demo as simple as http://blogs.embarcadero.com/pawelglowacki/2008/12/18/38624

What am I missing? What's wrong here? Very frustrating...

Upvotes: 2

Views: 4533

Answers (5)

Dino
Dino

Reputation: 11

Most likely issue you are having is that something on your apache module, perhaps your cgi script is causing a severe internal server error on Apache (HTTP 500). As a result, your apache is throwing an error but that error is in HTML, not XML format. So if you are working with webservices for example, you are expecting to get SOAP (which is XML) but you are getting HTML which is not recognized and as a result your app might show something like "xml document must have a top level element" or like in my case "Client found response content type of TEXT/HTML but expected text/xml". The worst yet, apache error.log will not show anything and access.log will show just 500 error (although I set it to Debug mode). I have used Wireshark to try to solve my problem. And what I found is confirmation of what I explained above but I have no solution yet for my problem.

Upvotes: 1

Ryan VanIderstine
Ryan VanIderstine

Reputation: 481

It most likely means you getting an HTML response from the server due to an error loading your SOAP library or an error within the SOAP library itself. The HTML cannot be parsed and results in this error.

A proxy can help you but you might want to have a look at Wireshark as it will allow you to sniff the traffic pretty easily and not specifically just for HTTP traffic.

Upvotes: 0

Reputation:

OK - this gets a little stranger ---

I've found that this all works under IIS but fails on apache (eed3si9n's solution DOES NOT work on apache)

Worse, I've found that under apache my basic cgi request content fields on POST are empty under apache - yet I simply deploy under IIS and it works just fine

So either the culprit is my apache install or there is something amiss under apache with delphi (surely that would be so widely reported and fixed)

So --- does anyone have any ideas what apache config options I should be looking at here?

Thank-you

Upvotes: 0

Eugene Yokota
Eugene Yokota

Reputation: 95624

Try setting the following options for HTTPSoapPascalInvoker.Options:

soRootRefNodesToBody
soUTF8InHeader
soUTF8EncodeXML

Upvotes: 1

Jan Remunda
Jan Remunda

Reputation: 7930

Probably you have wrong generated XML data. Every XML document must have a top level element:

<xml version="..">
<topLevelElement>
 <element>
   ...
 </element>
 <element>
   ...
 </element>
<topLevelElement>

If this root element is missing, deserializer throws an exception.

Upvotes: 0

Related Questions