0

我有一个 REST WCF 服务,它有一个将参数作为字符串获取的方法

当我在 URL 中使用 %23 时,我收到一条错误消息:找不到端点!例如:

-- Id #9999
http://localhost:8000/MyService/GetData/Id/%239999 (%23 means # symbol encoded)

如果我使用没有 % 符号,它工作正常

http://localhost:8000/MyService/GetData/Id/10

[ServiceContract]
public interface IService1
{
    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetData/id/{id}")]
    string GetData(string value);

}

我在 Windows 服务上托管服务:

        ServiceHost host = new ServiceHost(typeof(Service1), "http://localhost:8000");

        WebHttpBinding binding = new WebHttpBinding();

        ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IService1), binding, "MyService");
        WebHttpBehavior httpBehavior = new WebHttpBehavior();         
        endpoint.Behaviors.Add(httpBehavior);

        host.Open();

我找到了这篇文章: http ://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx但它不起作用,因为我没有在 IIS 上托管 WCF,而是在 Windows 服务上托管它

4

2 回答 2

1

由于这个线程,我找到了解决方案:
如何将斜杠和其他“url 敏感”字符传递给 WCF REST 服务?

解决方案:

<configuration>
  <system.net>
    <settings>
      <httpListener unescapeRequestUrl="false"/>
    </settings>
  </system.net>
</configuration>
于 2016-12-29T23:28:13.800 回答
0

在 url 中使用一些特殊字符不是最佳实践。请考虑不要使用它们。

看看MSDN - UriTemplate

于 2016-12-29T23:28:48.133 回答