0
GET工作,但是当POST被调用时,我的服务以不允许的405方法响应。WCF REST服务返回405用于POST
[ServiceContract]
public interface IRestMeraki
{
[OperationContract]
[WebInvoke(Method = "OPTIONS", UriTemplate = "")]
void GetOptions();
[OperationContract]
[WebGet(
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "json/")]
void JSONData();
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "json/{value}")]
void Post(string value);
}
}
和我的方法(GET选项reading this后试过)
public void GetOptions()
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
}
public void JSONData()
{
//my code here
}
public void Post(string value)
{
//my code here
}
我还添加了处理程序,我的网络配置文件
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="POST, GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
我不能更改URI使用每种方法都不同。我使用get进行验证并发布以接收数据。 Wireshark显示了这个405错误。
不,这不是。我甚至不记得我是如何工作的,因为我尝试了一切,并改变了网络配置中的一切,并最终改变了我的服务合同。但因为你是唯一回答的人。 – Redhead 2015-12-07 17:25:28