Reputation:
We have implmented a REST-style get service Using WCF in .Net 3.5. This service retrieves research documents. The string 'synopsis' indicated in the code bolow contains non-english characteres which the browser deliveres as "????????".
private void ReturnSynopsisInfo(IApiWebOperationContext context, OutgoingWebResponseContext outgoingResp, string synopsis) { SetResponseHeaders(outgoingResp, HttpStatusCode.OK); outgoingResp.ContentType = "text/html; charset=UTF-8"; context.Result = new MemoryStream(Encoding.ASCII.GetBytes(synopsis)); }
Any advise is much appreciated.
Thank You.
Upvotes: 0
Views: 672
Reputation: 42639
It seems you are declaring the encoding as utf-8 in the content-type header, but actually using ASCII encoding in stream. The ASCII encoder will silently change any non-ascii character into a question mark.
You probably want to use UTF8Encoding
rater than ASCIIEncoding
.
Upvotes: 1