I would like to know, in a wcf rest service is it possible to use both HTTP POST and HTTP Get in same method? I mean to say that a client page can either use post or get to invoke my method.
My client wants me to implement a method in this way.
As our API is a "RESTful" service we should be able to use both GET and POST with this method. The parameter can be placed in the URL of a GET request and also in the Header section of the GET request. When using a HTTP POST with this method the parameter can be stored in the header section or the body.
Is it possible?
Lets do it by writing code! Suppose you have a method!
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "Leads",
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
[WebGet(UriTemplate="/Leads")]
Result AddLeads(ReqLead[] rl); // This is our method.
When you will run your service, it will compiled and run successfully and browser will display you a page.
Now green arrow pointing is my Service name. By cliking on it will redirect you an error page and it will make an idea clear to you! See the image below.
I hope it will give you an idea. Moreover! In you [OperationContract]
you will define only one method type, whether GET or POST. You can't have both.
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With