Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF REST parameters cannot contain periods?

Tags:

So here's a super simple interface for doing rest in WCF.

    [ServiceContract]
    public interface IRestTest
    {
        [OperationContract]
        [WebGet(UriTemplate="Operation/{value}")]
        System.IO.Stream Operation(string value);
    }

It works great, until i try to pass a string with periods in it, such as a DNS name... I get a 404 out of asp.net.

Changing the UriTemplate to stick parameters into the query string makes the problem go away. Anyone else see this or have a workaround?

like image 331
John Ketchpaw Avatar asked Feb 04 '09 20:02

John Ketchpaw


2 Answers

That is true that a path part cannot contain a period or many other special characters for that matter. I experienced the same problem a while back and received an answer from TechNet team stating that querystring is your only option the could find. Sorry

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d03c8331-1e98-4d5d-82a7-390942a93012/

like image 116
bendewey Avatar answered Sep 19 '22 23:09

bendewey


I have a service with almost the exact signature. I can pass values that have a "." in the name. For example, this would work on mine:

[OperationContract]
[WebGet(UriTemplate = "category/{id}")]
string category(string id);

with the url http://localhost/MyService.svc/category/test.category I get the value `"test.category" passed in as the string value.

So there must be some other issue. how are you accessing the URL? just directly in the browser? Or via a javascript call? Just wondering if it is some error on the client side. The server passes the value just fine. I would recommending trying to access the url in your browser, and if it doesn't work then post exactly what URL you are using and what the error message was.

Also, are you using WCF 3.5 SP1 or just WCF 3.5? In the RESTFul .Net book I'm reading, I see there were some changes with regards to the UriTemplate.

And finally, I modified a simple Service from the RESTFul .Net book that works and I get the correct response.

class Program
{
    static void Main(string[] args)
    {
        var binding = new WebHttpBinding();
        var sh = new WebServiceHost(typeof(TestService));
        sh.AddServiceEndpoint(typeof(TestService),
            binding,
            "http://localhost:8889/TestHttp");
        sh.Open();
        Console.WriteLine("Simple HTTP Service Listening");
        Console.WriteLine("Press enter to stop service");
        Console.ReadLine();
    }
}

[ServiceContract]
public class TestService
{
    [OperationContract]
    [WebGet(UriTemplate = "category/{id}")]
    public string category(string id)
    {
        return "got '" + id + "'";
    }   
}
like image 45
christophercotton Avatar answered Sep 19 '22 23:09

christophercotton