Special character in WCF url $ no longer on WIndows 2012 with .NET 4.5

664 views Asked by At

I have a WCF REST API which uses uri templates. One of these Uri templates looks like this: [WebGet(UriTemplate="List/Data.svc/$count")].

In windows 2008r2 this url works fine, but fails on some 2012 servers. When I look at the logs (logs I internally write, not the IIS logs), the 2008r2 request looks like this:

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

The 2012 server url looks like this:

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

The exact same app on the same device is making both requests, so I am 99.999% sure this is not a difference in how the app is making the request.

Does WCF do any url encoding for incoming requests?

There are quite a few KB fixes related to .NET 4.5 on Windows Server 2012 for WCF, but I cannot find a comprehensive list, and I have not found one that seems to be related to this issue.

On a Windows 2012 server, if you go to .../test.svc/$test it works and you will see "test succesful!". If you do the same on a Windows Server 2012 r2 server, you will get "Bad!! This is not the right route!"

    [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));

    }
1

There are 1 answers

0
nicoleeschmidt On

There are two possible solutions to this issue. They are described in this blog post:

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

I tested both of these fixes and they work well for 2012r2.