This is my code for wcf web services
[OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "json2")]
StringMessageJson AddEmployee(EmployeeJson emp);
And this is my code in cs file of services
public StringMessageJson AddEmployee(EmployeeJson emp)
{
}
And here I am calling the webservice method through jquery ajax:
$('document').ready(function ()
{
var emp =
{
ID: '',
EmpName: 'Sk',
EmpID: 'A004',
Username: 'A@a.a',
Password: 'Aaa',
Address: 'Sec-001',
PhoneNumber: '09012312',
MobileNumber: '535345345',
EmpTypeID: '2',
EmpTypeValue: ''
};
var datatosend='{"emp":' + JSON.stringify(emp) + '}';
$.ajax(
{
type: "POST",
url: "http://localhost:6943/EmsRestApi.svc/json2",
data: datatosend,
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
success: function (resp)
{
Console.log(resp);
alert("Message\n'" + resp.Message + "'");
},
error: function (e)
{
//console.log(e);
alert(e);
}
});
$.support.cors = true;
});
And after running this I am getting error message on Chrome console:-
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
Please Help me to get rid off this issue.