这是我的WCF Web服务WCF REST服务邮政法JSON格式
[OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "json2")]
StringMessageJson AddEmployee(EmployeeJson emp);
代码,这是我在服务
public StringMessageJson AddEmployee(EmployeeJson emp)
{
}
在这里,我的CS文件代码我正在通过jquery ajax调用webservice方法:
$('document').ready(function()
{
var emp =
{
ID: '',
EmpName: 'Sk',
EmpID: 'A004',
Username: '[email protected]',
Password: 'Aaa',
Address: 'Sec-001',
PhoneNumber: '09',
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;
});
并运行此之后,我的Chrome控制台上收到错误消息: -
无法加载资源:服务器与405状态响应(不允许的方法)
请帮我摆脱解决这个问题。
查看相关答案(http://stackoverflow.com/a/14122895/1810429)FWIW。 – J0e3gan 2013-05-09 07:11:30
当我通过谷歌浏览器中的开发人员工具进行检查时,它显示** GET **请求正在发送而不是Post。 – Sonu 2013-05-09 07:27:13