0

I have a RESTful service with WCF. It has an interface with a method

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "AddBook/{bookName}", BodyStyle =     WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
void AddBook(string bookName);

and my service localhost:1234/MService/AddBook/abcd-book is working. But if I change GET to POST, it says method not allowed. I thought, inserting should be POST but it is not working. Am I wrong or doing something wrong with the coding above?

Regards

cissharp
  • 216
  • 1
  • 11
  • 1
    Your method is only allowing GET according to the attribute. 'WebInvoke(Method = "GET"' – John Hartsock May 06 '14 at 19:24
  • But if I change that GET to POST and try to add book from URL, it says method not allowed. – cissharp May 06 '14 at 19:34
  • REmove it all together like this: WebInvoke(UriTemplate = "AddBook/{bookName}", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json) – John Hartsock May 06 '14 at 19:38
  • Thank you John. But I tried that already without success. – cissharp May 06 '14 at 19:41
  • http://stackoverflow.com/questions/23153700/can-wcf-restful-service-allow-same-method-expose-as-webget-and-webinvoke – Marvin Smit May 06 '14 at 19:50
  • 1
    What do you mean by `try to add book from URL`? Do you type the URL on a browser window? How do you create your POST request? – YK1 May 06 '14 at 19:50
  • @YK1: I think that is the problem. I tried POST request like GET with URL on a browser window. – cissharp May 06 '14 at 20:01
  • 2
    Yes, typing URL in browser will send GET request by default. To send a POST request, either create a HTML form or use tool like Fiddler. – YK1 May 06 '14 at 20:04
  • Can you post your comment as answer so that I can mark it as answer? – cissharp May 06 '14 at 20:05

1 Answers1

1

Typing URL in browser will send GET request by default. To send a POST request, either create a HTML form or use tool like Fiddler.

YK1
  • 7,327
  • 1
  • 21
  • 28