Reputation: 2815
I am working on a WCF REST service, and in the service I have two methods with the same URITemplate. One of them is marked with a WebGet and the other with a WebInvoke using PUT as the method.
[WebGet(URITemplate="{name}")]
public Something GetSomethingNamed(string name)
[WebInvoke(Method="PUT", URITemplate="{name}")]
public Something AddSomethingNamed(Something somethingToAdd)
When trying to test something in the service, best way to handle an exception, by attempting to browse to the GET method in IE I received an error that AddsomethingNamed required a parameter named NAME.
I am slightly baffled by this response as I don't even know how it was getting to the PUT method, from what I know web browsers don't even directly support PUT.
Upvotes: 0
Views: 202
Reputation: 1000
[WebInvoke(Method="PUT", URITemplate="{name}")]
public Something AddSomethingNamed(Something somethingToAdd)
In your above code in the URI template you mentioned {name} which means that your method accepts one more parameter "name".
So your method signature should be either of the following
[WebInvoke(Method="PUT", URITemplate="AddSomethingNamed")]
public Something AddSomethingNamed(Something somethingToAdd)
OR
[WebInvoke(Method="PUT", URITemplate="{name}")]
public Something AddSomethingNamed(string name, Something somethingToAdd)
Upvotes: 1