>What are you using for your Web Service? ASMX or WCF?
ASMX
>Both mechanisms support methods you can implement on the service to inject custom data into the document. It's not trivial and you'd have to inspect each response to decide whether you need to actually inject. You can't just put XML at the top of the page (or end) because as you found out that produces invalid XML - the XML has to become part of the XML document. Typically in SOAP this is done with custom SOAP Headers. You can effectively define a custom SOAP Header and then set that header for the requests that need it.
I suspected that.
>It's been a long while since I looked at this and it's ugly. Really what you should do is add that functionality to the main SOAP envelope and the payload you're sending. A common way to do this is a common Request and Response object structure that includes message specific objects (like hasErrors,errorCode, etc.) which then has a content element into which you push your actual result data. It's a pretty common service pattern that works really well. You basically create a base ResponseMessage object and you can then subclass that to add the custom result properties that you need to actually return to the client. Most enterprise systems use a variation of this message based service style.
I have all that. This is as is for regular Web Service method handlers. But, for as long as I am not in the Web Service method, thus at a very high level, I have one specific place which I need to intercept, based on a very rare condition, the request and return a custom message.
I have a SOAP trace extension which might be useful for that. I will have to do more research on this.