I have a simple .net web service published in IIS:
[OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "formTestGET?firstInput={firstInput}&socondInput={socondInput}")] string formTestGET(string firstInput, string socondInput); [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "formTestPOST")] string formTestPOST(string testInput);
Method Implementation:
public string formTestGET(string firstInput, string socondInput) { try { return "First Input value: " + firstInput + " Second Input value: " + socondInput; } catch (Exception e) { return e.Message; } } public string formTestPOST(string testInput) { try { return "Post paramether value: " + testInput; } catch (Exception e) { return e.Message; } }
My html form:
<form method="post" action="http://localhost/HTML5RestfulService/Service1.svc/formTestPOST"> <fieldset> <legend>Form Post Request</legend> <input name="testInput"/> <button>Make Post Request</button> </fieldset> </form>
I just want to use this service in html form. I have a problem with my POST method. It works fine when I call it using Ajax (from a java script), but through the form I can not get the answer. I get a "400 Bad Request" as an error.
Do I have to configure my WS differently when I want to call it through FORM?
Any advice please.
Milos source share