views:

303

answers:

1

Hello everyone,

I am developing a Web Services based on ASP.Net asmx web service. The server end will response byte[] to client encoded in UTF-8, and client to convert the byte[] to string.

My confusion is, the England pound character at server side (I dump just before the Http response is wrote, and the character at server side is correct to be England pound) will be received as ?? from client side.

Any ideas what is wrong? I suspect it is encoding issue, but I have no idea how to debug further and any settings (settings from client web service proxy?) which will impact?

thanks in advance, George

Here is the header part which I got from Fiddler.

HTTP/1.1 200 OK Date: Fri, 20 Feb 2009 16:51:30 GMT Server: Microsoft-IIS/6.0 cache-control: no-cache pragma: no-cache X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/xml Content-Length: 22752

xml version="1.0" encoding="utf-8"

+1  A: 

The first thing to do is to sniff what's actually being sent, in terms of the headers, the XML declaration and the bytes forming the text itself.

Fiddler is good as an HTTP proxy, or you could use WireShark to sniff at the network level.

Once you've got those three bits of information (the Content-Type header, the XML declaration and the bytes making up the pound sign) if you update your answer we'll see what we can do. It does sound odd, as usually ASP.NET just gets all of this right.

What does your client side code look like? Is that just the normal .NET web service client code as well?

EDIT: Try to find a binary (hex dump) display in Fiddler so you can find the bytes.

However, I strongly suspect that the problem is merely with dumping the result to the console. Here's a bit of code to use to dump the unicode code points:

static void DumpString (string value)
{
    foreach (char c in value)
    {
        Console.Write ("{0:x4} ", (int)c);
    }
    Console.WriteLine();
}

I suspect you'll see an 00A3 in the output, which is the Unicode for the pound sign. That means the string has actually reached your client fine - but writing it out to the console is failing.

Jon Skeet
I have just used Fiddler and posted the response. Any ideas, guru? :-)
George2
I found in Fiddler, the content is correctly displayed as England pound, but in the string return value I got, the content is ?? (I dump it to Console and see ??).
George2
I find US dollar sign could be displayed correctly. Does it mean default encoding UTF-8 does not work for England pound but works for U.S. dollar? :-)
George2
$ is part of ASCII, whereas the pound sign isn't. I've edited my answer - I strongly suspect it's just your console rather than the web service client, but I've given you some code to check.
Jon Skeet
Jon, I have followed your solution to debug it, it is displayed as 003F 003F for ??, and not 003A. Any ideas?
George2
That sounds very odd. Could you show your client code?
Jon Skeet
I have debugged in Hex view in Fiddler, the related value is C2 A3 for England pound, any ideas?
George2
C2 A3 is correct for the UTF-8 encoding of U+00A3 - so it's definitely in the client code somewhere. Given that the XML explicitly specifies UTF-8, this is very strange.
Jon Skeet
Jon, my client code is very simple, just receive a C# string and wrote to console. From our discussion, Fiddler could display England pound, I think it means the content is correct on wire? I suspect something wrong when cient proxy built-in code decode issue. Any comments or ideas?
George2
I could get ?? from two places, from Console.writeline and from stop mouse pointer on the string variable from server. Any ideas what is wrong?
George2
"C2 A3 is correct for the UTF-8 encoding of U+00A3" -- it proves the on wire content is correct. But something wrong when the automatically generated proxy decodes UTF-8 bytes into string?
George2
I have a new idea, are there anything wrong with my current locale setting? I am running Windows Server 2003 x64 on client side.
George2
Yes, it sounds like it. By "client" I mean "code which receives the response from the server and decodes it" btw.
Jon Skeet
Hi Jon Skeet, besides the web service client proxy code generated by "Add Web Reference" directly, I do not add any additional code. Any comments and ideas what is wrong and investigate further?
George2
So it's just the normal cilent code - that really should work fine. Is this just a web method returning a string?
Jon Skeet
At server side, it is an ashx handler which finally wrote SOAP message as byte[] to response stream of current HttpContext. I think from the result of Fiddler, the information should be correct on wire, correct (so, I assume server is correct)? Any ideas?
George2
Well it certainly looks correct from what you've told us, but it's tricky to say for certain - there may be some important bit of information that we're missing. What's the ashx handler doing, exactly? What happens if you just talk directly to the SOAP handler instead?
Jon Skeet
Hi Jon Skeet, I am checking my ashx code, but now I suspect more about client side issue other than server side issue, since the Fiddler display the correct information. And one more quick question, what factors at client may impact the decoding results? Any settings in client proxy itself?
George2