突然我收到一个错误“方法不允许。” 从如下 HTML 表单调用 WCF REST POST 服务时(它在开发、UAT、生产环境中早期工作,但现在失败。
是什么导致了这个问题?什么是潜在的解决方法?
<form action="http://localhost:8750/MyService/MyEmailService/RecordResponse" method="post" runat="server">
<div align="left">
<input type="hidden" name="userid" value="abc">
<input type="hidden" name="itemid" value="625">
<select name="response">
<option value="Approved">Approve</option>
<option value="Rejected">Reject</option>
</select>
<textarea cols="40" rows="5" name="comment">Add comments here</textarea>
<input type="Submit" value="Submit">
</div>
</form>
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class MyEmailService: IMyEmailService, ISessionAwareService
{
[OperationContract]
[WebInvoke(UriTemplate = "/RecordResponse", Method = "POST")]
public void RecordResponse(Stream stream)
{
// My business logic
}
}
配置如下:
<endpointBehaviors>
<behavior name="webby">
<webHttp helpEnabled="true"/>
</behavior>
<service name="CTRL.Server.CommandHandlerService.EmailHandlerService">
<endpoint address="http://localhost:8750/MyService/MyEmailService"
binding="webHttpBinding"
contract="MyService.ServiceContracts.IEmailService"
behaviorConfiguration="webby"/>
<webHttpBinding>
<binding name="secure">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>