Click here to Skip to main content
15,886,065 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi experts,
When I enter some Unicode (UTF-8) characters in my query string, it will change in my program.

C#
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
             ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class RestServices : IRESTServices
{
    public Stream GetClientNameById(string id, string message)
    {
        string ReturnString = string.Format("id={0} and message ={1}", id, message);
        return GenerateStreamFromString(ReturnString);
    }

private Stream GenerateStreamFromString(string s)
{
    MemoryStream stream = new MemoryStream();
    StreamWriter writer = new StreamWriter(stream, Encoding.GetEncoding("utf-8"));
    writer.Write(s);
    writer.Flush();
    stream.Position = 0;
    return stream;
}

}


the message will change, if I enter the address below:
http://localhost:8000/DEMOService/subscribe?userID=14953828&message=مرحبا

It will change to ÓáÇã

How can I use utf-8?

This is the interface:
C#
[ServiceContract(Name = "RESTDemoServices")]
[XmlSerializerFormat]
public interface IRESTServices
{
    [OperationContract]
    [WebGet(UriTemplate = Routing.GetClientRoute, BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json)]
    Stream GetClientNameById(string id, string message);
}


And:
C#
public static class Routing
{
    public const string GetClientRoute = "/subscribe?userID={id}&message={message}";
}


Thank you
Posted
Updated 13-Sep-13 10:16am
v3
Comments
Mehdy Moini 14-Sep-13 8:13am    
did you test percent encoding in creating your url?
http://en.wikipedia.org/wiki/Percent-encoding
mariazingzing 14-Sep-13 12:09pm    
No but how can I do this?
Mehdy Moini 14-Sep-13 12:56pm    
I think when you encode by utf-8 actually you decode percent encoding which is default of browser, just i guess.
mariazingzing 16-Sep-13 14:59pm    
Thank you but may you give me a solution? Is it impossible to correct my code or something that works?
Mehdy Moini 17-Sep-13 0:44am    
use this tag in your page header i think it solve problem:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900