This question is asked a lot, but even though I tried the solutions they offered, I still get an error.
I am sending a post request with a Person object as a parameter, but i get:
405 - Method Not Allowed error"
code:
contract:
[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; }
}
service:
public class PayMentService : IPayMentService
{
public void AddPerson(Person person)
{
//..logic
}
}
client:
$(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'
})
});
Thanks,