1

我有一个使用 uri 模板的 WCF REST API。其中一个 Uri 模板如下所示:[WebGet(UriTemplate="List/Data.svc/$count")]。

在 Windows 2008r2 中,此 url 工作正常,但在某些 2012 服务器上失败。当我查看日志(我内部编写的日志,而不是 IIS 日志)时,2008r2 请求如下所示:

"http://myserver:40217/List/Data.svc/$count"

2012 年的服务器 URL 如下所示:

"http://myserver:40217/List/Data.svc/%24count"

同一设备上的完全相同的应用程序同时发出了两个请求,所以我 99.999% 确信这与应用程序发出请求的方式没有区别。

WCF 是否对传入请求进行任何 url 编码?

在 WCF 的 Windows Server 2012 上有很多与 .NET 4.5 相关的 KB 修复,但我找不到一个完整的列表,而且我还没有找到一个似乎与此问题相关的列表。

在 Windows 2012 服务器上,如果您转到 .../test.svc/$test 它可以工作,您将看到“测试成功!”。如果您在 Windows Server 2012 r2 服务器上执行相同操作,您将收到“糟糕!这不是正确的路线!”

    [WebGet(UriTemplate = "$test")]
    public System.IO.Stream GetTest() 
    { 
        return new MemoryStream(System.Text.Encoding.UTF8.GetBytes("test succesful!")); 
    }

    [WebGet(UriTemplate = "{id}")]
    public System.IO.Stream GetById(string id) 
    {
        if (id == "$test")
            return new MemoryStream(System.Text.Encoding.UTF8.GetBytes( "Bad!! This is not the right route!"));
        else
            return
                new MemoryStream(System.Text.Encoding.UTF8.GetBytes("You did a get by Id on " + id));

    }
4

1 回答 1

1

这个问题有两种可能的解决方案。这篇博文中描述了它们:

http://blogs.msdn.com/b/asiatech/archive/2014/01/24/case-study-wcf-web-http-routes-dollar-differently-in-iis-8-5.aspx

我测试了这两个修复程序,它们在 2012r2 中运行良好。

于 2014-01-24T16:33:26.037 回答