Consuming wcf restservice webinvoke post method with jquery ajax getting error 'method not allowed' [Resolved]

Posted by raghuavulapalli-25110 under WCF on 12/26/2013 | Points: 10 | Views : 3808 | Status : [Member] | Replies : 3
I have implimented post method in wcf rest service and hosted it in IIS. I tried to consume the service using jquery ajax but getting error 'method not allowed'.

Here is my code

Declaration in Iservice.cs

[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/AddNewEmployee", RequestFormat = WebMessageFormat.Json)]
[OperationContract(Name = "JsonData")]
List<Employee> AddNewEmployee(Employee oEmployee);

Implimented it service.svc.cs

public List<Employee> AddNewEmployee(Employee oEmployee)
{

try
{
List<Employee> oListEmployee = Helper();
oListEmployee.Add(new Employee()
{
Address = oEmployee.Address,
Designation = oEmployee.Designation,
Email = oEmployee.Email,
EmployeeID = oEmployee.EmployeeID,
Employeename = oEmployee.Employeename
});
return oListEmployee;

}
catch (Exception)
{
return null;
}
}

Ajax code

var Employee = { "EmployeeID": "10", "Employeename": "raju", "Designation": "SE", "Address": "OU", "Email": "mail@mail.com" };

var data = JSON.stringify(req);

$.ajax({
type: "Post",
url: "http://192.168.1.17:8569/service1.svc/AddNewEmployee",
datatype: "json",
data: JSON.stringify(Employee),
ContentType: "application/json; charset=utf-8",
processData: true,
success: function (xml) {

alert(xml);

},
error: function (err) {
alert("error=>" + err);
}
});

Raghunath


Responses

Posted by: kgovindarao523-21772 on: 1/2/2014 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

Here is the solution:

var Employee = '{ "EmployeeID": "10", "Employeename": "raju", "Designation": "SE", "Address": "OU", "Email": "mail@mail.com" }';



$.ajax({
type: "Post",
url: "http://192.168.1.17:8569/service1.svc/AddNewEmployee",
datatype: "json",
data: Employee,
contentType: "application/json; charset=utf-8",
processData: true,
success: function (xml) {

alert(xml);

},
error: function (err) {
alert("error=>" + err);
}
});


Thank you,
Govind

raghuavulapalli-25110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 12/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
I got you problem.
Check if it working in IE?

raghuavulapalli-25110, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: raghuavulapalli-25110 on: 12/26/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Allemahesh,
It's not working in IE too... even am not getting error message in IE.
I checked the console for error in browser tool by clicking f12 it showed SCRIPT5: Access is denied.
In mozilla getting error message [object XmlHttpRequest]

Raghunath

raghuavulapalli-25110, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response