我跟着这篇精彩的帖子 SharePoint 2013: Create a Custom WCF REST Service Hosted in SharePoint
现在,当我调用“GET”请求时,一切都按预期工作。我的“POST”请求问题,它总是返回404找不到错误响应!
[OperationContract]
[WebInvoke( Method = "POST",
UriTemplate = "Approve",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
bool Approve(PendingMeRequest pendingRequest);
批准实施很简单并返回true
public bool Approve(PendingMeRequest pendingRequest)
{
return true;
//SPUser currentuser = SPContext.Current.Web.CurrentUser;
//return Take_approval_action(pendingRequest, "approve", currentuser.LoginName);
}
PendingMeRequest模型很简单,包含3个字符串字段
public class PendingMeRequest
{
public string Key { set; get; }
public string RequestedBy { set; get; }
public string RequestTitle { set; get; }
}
当我用jquery调用这个方法时,我得到404找不到错误
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/UnifiedWorklistService.svc/Approve/',
method: 'POST',
dataType: 'JSON',
data: JSON.stringify({pendingRequest: obj}),
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert(data);
}
});
我试图从POSTMAN调用它,但我得到了同样的错误
我想我错过了Sharepoint配置的一些东西,但我无法弄清楚
更新
经过几个小时的搜索后我终于发现了问题,应该删除ajax调用/_vti_bin/UnifiedWorklistService.svc/Approve/
中的尾部斜杠!
我无法相信我浪费时间去弄明白......