从过去几个小时开始,我一直在努力,但没有上路。感谢您提前提供的任何帮助。
我的合约代码:
[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 服务是可以的。但是传递的员工对象为 null 如何解决此问题。