我正在尝试做简单的WEB服务。我基于本文的代码:
http://www.progware.org/Blog/post/A-simple-REST-service-in-C.aspx
我做了一点修改,所以我的服务可以得到几个参数。
这是我的更改:

 public string GetClientNameById(string LS, string Owner, string info)
{
 .....
 return System.IO.File.ReadAllText(XMLFileName, Encoding.GetEncoding(1251));
}
[ServiceContract(Name = "RESTServices")]
    public interface IRESTServices
    {
        [OperationContract]
        [WebGet(UriTemplate = Routing.GetEPDRoute, BodyStyle = WebMessageBodyStyle.Bare)]
        string GetClientNameById(string Id,string LS,string tmp);
    }
public static class Routing
    {
        public const string GetEPDRoute = "/EPD/{id}+{LS}+{tmp}";
    }


它可以与英语simbols一起正常工作,但我需要使用西里尔simbols。
如果我在网址中使用西里尔simbols,则会返回404错误。
我尝试使用百分比编码,但结果相同
这是我的客户代码:

string url = "http://localhost:4385/Service.svc/EPD/995118466+" + System.Uri.EscapeDataString("Аксенова") + "+434";
            WebRequest req = WebRequest.Create(url);
            using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(resp.GetResponseStream());
                label1.Text = reader.ReadToEnd();
            }


任何想法如何解决这一问题?

更新:我找到了一个解决方案-只是用数字代码代替了非英语的simbols,但是我想找到更优雅的解决方案

最佳答案

<globalization
      requestEncoding="utf-8"
      responseEncoding="utf-8"
      responseHeaderEncoding="utf-8"
      fileEncoding="utf-8"
      resourceProviderFactoryType=""
      enableBestFitResponseEncoding="true"/>


在web.config全球化标签中添加thease参数

然后用这样的东西

//UTF-8
HttpUtility.UrlDecode(parameter, System.Text.Encoding.UTF8)
//UTF-16
HttpUtility.UrlDecode(parameter, System.Text.Encoding.Unicode)
//UTF-32
HttpUtility.UrlDecode(parameter, System.Text.Encoding.UTF32)


希望能帮助到你

08-28 03:35