【发布时间】:2019-08-10 19:26:13
【问题描述】:
这个问题被问了很多,但即使我尝试了他们提供的解决方案,我仍然得到一个错误。
我正在发送一个带有 Person 对象作为参数的发布请求,但我得到:
405 - 方法不允许错误"
代码:
合同:
[ServiceContract]
public interface IPayMentService
{
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/AddPerson",
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
void AddPerson(Person person);
}
[DataContract]
public class Person
{
[DataMember]
public int Id { get; set; }
[DataMember]
public int Age { get; set; }
[DataMember]
public String Name { get; set; }
}
服务:
public class PayMentService : IPayMentService
{
public void AddPerson(Person person)
{
//..logic
}
}
客户:
$(document).ready(function() {
var person = {Id: 1, Age : 13, Name: "zag"};
$.ajax({
url: 'http://localhost:64858/PayMentService.svc/AddPerson',
type: 'POST',
contentType: "application/json",
data: JSON.stringify(person),
dataType: 'json'
})
});
谢谢,
【问题讨论】:
-
你在使用 IIS 吗?
-
我正在使用 IIS express
-
请先尝试副本中的每个建议,然后再说副本不起作用。