I have a REST WCF service that has a method that gets a parameter as a string
When I use the %23 in the Url I got an error message: Endpoint not found! e.g:
-- Id #9999
http://localhost:8000/MyService/GetData/Id/%239999 (%23 means # symbol encoded)
If I use without % symbol it works fine
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);
}
I Host the Service on Windows Service:
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();
I've found this post: http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx but it doesn't work since I'm not hosting WCF on IIS I'm hosting it on Windows Service instead
I found the solution thanks to this thread:
How can I pass slash and other 'url sensitive' characters to a WCF REST service?
Solution:
<configuration>
<system.net>
<settings>
<httpListener unescapeRequestUrl="false"/>
</settings>
</system.net>
</configuration>