3

I have a client submitting a web-request (POST) of XML data to a server. The head of the XML reads <?xml version="1.0" encoding="utf-16"?> but the data is truly utf-8. We are trying to intercept the existing stream (and everybody involved realizes this, we're trying to put in a store-and-forward so if there's any downtime we can at least buffer the requests) but IIS seems to be rejecting the XML because the actual encoding doesn't match the stated encoding.

If we manually (using a string as our originating value in a test-client app) force the encoded bytestream and set the encoding value within the string to either UTF-32 or UTF-8 in C# and shove it into our WCF method, it works fine.

But sending in UTF-8 encoded values with a header in the file that reads UTF-16, it bombs out. Lastly, and most exasperatingly, I'm not the primary dev on this, I've had my eyes on it a grand total of 6 hours over 4 days, and I'm being tasked from on high with finding a spare bit of magic laying about. Anybody got some ideas?

So my issue is with either IIS or ASP.NET, I realize that. I'm just not sure what and where to kick this damned thing, and not sure what details I'm missing for the question. I did hash this out in the chatroom prior to posting here, and a few details more were unearthed, but if you have questions, I'm open to answering them, as I can. You just ask what you want to see, and I'll share. And I'm going to forego going ahead and posting lots and lots of C# and web.config code because, honestly, I don't know what's the best starting point to approach this particular problem.

So there's no way to fix the header on the client end?

Not at this time. Just spent 30 minutes on a group support call, and their primary dev for this project is out for the next 10 days, and our sales group has promised our product up by the end of this week

Does it throw an error that could be trapped?

No. The client reports a 400 error. That's the extent of our ability to track this puppy down, right now. I'm hoping somebody here with more familiarity on IIS fixes that for me ;)


So I'm looking for either

  • an ASP.NET or IIS solution that allows me to tell the input that I don't care what it's stated encoding is, tyvm, I know better, OR
  • a WCF way of intercepting the stream before it hits my class methods and then rewrite the string on the fly by examining for the <?xml version="1.0" encoding="utf-16"?> on this particular request.
4
  • Does it throw an exception anywhere useful? If so you could trap that and carry on.
    – ChrisF
    Dec 6, 2010 at 23:19
  • Excellent question @ChrisF ~ No. The best it does is kick a 400 back to the client. I'll update the question.
    – jcolebrand
    Dec 6, 2010 at 23:21
  • Tell us again why you don't just fix your code to stop lying about the XML encoding? Dec 7, 2010 at 0:38
  • Cos the WCF never fires any methods since IIS appears to kick the request sooner than my methods getting called? Sent from my iPhone
    – jcolebrand
    Dec 7, 2010 at 1:01

1 Answer 1

0

You might consider implementing you're own decoder. See the following SO question: Configuring the .NET WCF UTF-8 deserializer to modify/discard non-shortest form chars instead of throwing an exception?

5
  • @ChrisLively ~ Any thoughts/experience RE: MessageInspector vs MessageEncoder? (asks the n00b who has no clue what a MessageInspector is...)
    – jcolebrand
    Dec 7, 2010 at 0:17
  • 2
    @drachenstern: A MessageInspector is an extensibility component which can be inserted into the WCF dispatcher stack to examine a WCF message (and perform some action based on it) as it passes by. A MessageEncoder lives much deeper in the stack, close to the raw bytes sent over the network. Here, you'd need the latter, because unless you fix the decoding as the message comes off the wire, you'll not have a valid WCF message for a Message Inspector to see. Dec 7, 2010 at 13:51
  • @ChrisDickson ~ Excellent writeup, I appreciate that. Do you have any good resources for a visual depiction of the stack like that and where bits fall into play? I do need to get closer to the raw bytes, so I can see that the MessageEncoder is what I'm going to need. Thanks!
    – jcolebrand
    Dec 7, 2010 at 14:53
  • 1
    Will accept as answer but wanted to offer followup: Offending sender has several other bugs to fix in this particular module (phone numbers presented as float for starters, replete with truncation) so the onus is back on them to fix. Will mark as answer. Thanks for playing.
    – jcolebrand
    Dec 8, 2010 at 1:00
  • @drahenstern: sorry to hear about the screwed up situation. Good luck!
    – NotMe
    Dec 8, 2010 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.