我在过去的几个小时里一直在努力,但没有上路。谢谢你提前帮忙。
我的合约代码:
[WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Employee", BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract]
void PutEmployeeAccount(Employee obj);
我的服务代码
public void PutEmployeeAccount(Employee obj)
{
// obj passed is null
}
我的AngularJS代码
var myApp = angular.module('myApp', ['ngResource']);
myApp.factory('resourceService', function ($resource) {
var src = $resource("../EmployeeService.svc/Employee/:id",
{ id: "@id" }, //parameters default
{
GetData: { method: "GET", params: {}, isArray: true },
GetDataById: { method: "GET", params: { id: 0 }, isArray: true },
Delete: { method: "DELETE", params: { id: 0 }, isArray: true },
Update: { method: "PUT", params: {}, isArray: true },
save: { method: "PUT", params: {}, isArray: false }
});
return src;
});
function EmployeeCtrl($scope, resourceService) {
var Employee = new resourceService();
Employee.Employeename = 'bar';
Employee.$save();
}
对于PutEmployeeAccount,调用Web服务是可以的。但是传递的employee对象为null 我该如何解决这个问题。
答案 0 :(得分:0)
问题通过点击和试用解决,设置BodyStyle = WebMessageBodyStyle.Bare解决了这个问题。