1

I use WCF and have a method like this:

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "LoadProducts/{key}/{price}")]
XmlDocument LoadProducts(string key, string price= null);

price is string, inside LoadProducts I will try to parse it from string to double and do my other operations.

But in url, I can not get request any parameter for price like '24.25', '0.253' etc. It does not allow any value with dot.

localhost:13448/RestService.svc/LoadProducts/null/41.145

I get error "Please review the following URL and make sure that it is spelled correctly. "

How can I solve this?

Jeyhun Rahimov
  • 3,769
  • 6
  • 47
  • 90
  • 1
    A [dot is not allowed in a URL](http://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid) – Liam Oct 28 '13 at 13:43
  • I change my question some, Because I dont use it in my asp application. I deployed WCF application separately. – Jeyhun Rahimov Oct 28 '13 at 13:45
  • It doesn't matter what's calling it. Whatever is passing the dot in the URL needs to encode it (like the answer below). Dots are not valid in URLs except for extensions. – Liam Oct 28 '13 at 13:50

2 Answers2

4

Dots already have a meaning in a URL, they separate the target hostname, IP address or in the path they separate the resources from its extension. You will need to URL encode your request URL.

In .NET there is a method called UrlEncode to help you encode URLs. It is:

string url = "http://localhost/MyService/MyKey/24.25";

string encodedUrl = HttpUtility.UrlEncode(url);

Check out the MSN documentation for UrlEncode for more details.

Adrian Thompson Phillips
  • 6,893
  • 6
  • 38
  • 69
1

I solved my issue. I switched server from Visual Studio Development Server to Local IIS Web Server, url took dot symbol inside parameter.

Jeyhun Rahimov
  • 3,769
  • 6
  • 47
  • 90