The server committed a protocol violation

For the longest time I was having problems calling my WCF server, where the message in the exception I got client side was this:

"The server committed a protocol violation. Section=ResponseBody Detail=Response chunk format is invalid"

For the longest time I had no clue as to what was going on. I tried searching the web, but I found very few (only a hand full, I think) references, and none of those references seemed to make sense in my context (actually, I am hoping that this post will get indexed such that people facing the same may hit this post and maybe be helped out. I know... The good samaritan!). I tried enabling tracing, but I didn't see anything that jumped out at me. It has to be said, though, that I am by no means a master at reading those traces. I tried using Fiddler, but for some reason that caused to halt the response from my service to the client -- I still have to work out why that is. I tried with Network Monitor, but I drowned in the sea of frames it reported.

I enlisted the help of some of the people in the WCF framework team, and pretty quickly, we got some traction. The first thing that stood out was that the communication between client and the server was chunked. In the HTTP 1.1 spec, it states that if you use chunking, you (the server) has to provide the chunking length. In my case that was missing. After further input from the WCF people, the solution was very simple: Before returning the message to the client, simply clear all properties on the message (using Properties.Clear() on the message in question).

I hope this will help those of you who are unfortunate enough to run into this one.

EDIT: After talking a bit more to the people in WCF, it turns out that this is most likely expected behavior. See this MSDN article, specifically the "Working with Properties" section. Specifically, this sentence explains it:

"Normally, property values do not map directly to any part of the message on the wire, but rather provide various message processing hints to the various channels in the WCF channel stack or to the CopyTo service framework"