IIS で公開されているシンプルな .net restful Web サービスがあります。
[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 メソッドに問題があります。(Javaスクリプトから)Ajaxで呼び出すと正常に動作しますが、フォームからは応答が得られません。エラーとして「400 Bad Request」が表示されます。
FORM を使用して WS を呼び出したい場合、WS を別の方法で構成する必要がありますか?
アドバイスをお願いします。