views:

116

answers:

2

I have a RESTful WCF service which accepts GET verbs with Unicode encoded urls. The Unicode characters are translated as little boxes strangely when I get the data on the server.

Is there something I have to tell the service contract to do in order to get Unicode UrlEncoded Gets to translate into nice strings?

Here's my contract:

[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/Document/{Fragment}", RequestFormat = WebMessageFormat.Xml)]
Message GetDocumentFromSearchResult(string Fragment);

Here's a sample of the unicode I pass in: %FF%FE%22%00O%FF%FE%20%00King%FF%FE%20%00of%FF

I get "King" and "of" ok, but the rest are little of the string are little squares.

Gotta be an decoding issue ??

A: 

Examine the characters using Fragment[i] to see what the actual characters are. That will remove the variable of what the Debugger or other output method may be showing you.

John Saunders
+1  A: 

What you are passing in looks strange: it appears to contain UTF-16 for the " character with Byte Order Marks. This is almost certainly a problem, so it looks more like an issue with your encoding of the input.

Usually, UTF-8 is used for URLs, as this fits much better with the protocol (no need to escape all of the NUL bytes in pure ASCII). This is likely to be what your service is expecting, so it doesn't decode correctly (as %FF%FE is not valid UTF-8).

Michael Madsen