Jump to content
Mark Williams

TWebModule response content truncated before return

Recommended Posts

I'm using TWebModule in an ISAPI DLL. I am using it to return data from a database in xml format using IXMLDocument. Last night I had a problem with text data which included characters such as  "/". I assume the returned text was being formatted somewhere along the line to insert escape characters with the result that the received xml at the other end is always slightly short so that you end up with a badly formed xml document. So, for example, if the returned text had two "/" characters the xml document when received is short the last two characters. 

My code on the server side is:

Response.Content := doc.XML.Text;
Response.ContentLength :=length(doc.XML.text);

I also tried determining the ContentLength using "length(Response.Content)", but that made no difference.

 

I edited the data in the database to remove the "/" characters and all worked fine.

 

I have now tried to replicate the problem so that I can seek some advice as to possible causes, but the xml is no longer being truncated. 

 

I am puzzled and keen to avoid the issue for the future, but unable to provide any more info because I can't now replicate the problem. 

 

Does anyone have any ideas as to what may have caused the problem initially?

 

 

Share this post


Link to post
8 hours ago, Attila Kovacs said:

I have no clue, but you could watch this video, how to create a console application from the broker to be able to debug your code.

 

No video link? However, don't think it would help. There is no exception and in any event my code is wrapped in try...except statements with exceptions outputted to a log file. Also, as mentioned in my post I cannot now reproduce the problem and don't understand why it was happening in the first place. I am just keen to avoid a repeat.

Share this post


Link to post

Simple assignment to Content should be sufficient:

Response.Content := doc.XML.Text;

This will both encode the incoming string value and set ContentLength automatically. (See TISAPIResponse.SetContent in Web.Win.IsapiHTTP.)

In your case the encoded stream was longer than the original text, e.g. due to insertion of escape characters. By setting ContentLength explicitly you have effectively truncated the encoded stream.

  • Like 1

Share this post


Link to post
6 minutes ago, Ondrej Kelle said:

Simple assignment to Content should be sufficient:


Response.Content := doc.XML.Text;

This will both encode the incoming string value and set ContentLength automatically. (See TISAPIResponse.SetContent in Web.Win.IsapiHTTP.)

In your case the encoded stream was longer than the original text, e.g. due to insertion of escape characters. By setting ContentLength explicitly you have effectively truncated the encoded stream.

That makes sense. Many thanks.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×