4
我有IIS发布简单的.NET RESTful Web服务:WCF的REST类型的WS POST方法和HTML表单
[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);
的方法实现:
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;
}
}
我的HTML表单:
<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>
我只想通过html表单来使用此服务。我的POST方法有问题。当我使用Ajax(从java脚本)调用它时,它工作正常,但通过表单我无法获得响应。 我收到“400错误请求”作为错误。
当我想通过FORM调用它时,我应该不同地配置我的WS吗?
请提供任何建议。