【发布时间】:2015-09-01 03:33:41
【问题描述】:
这里是代码sn-ps。
1.复杂对象:
[DataContract]
public class NewUser
{
[DataMember(Name = "Email")]
public string Email { get; set; }
[DataMember(Name = "FirstName")]
public string FirstName { get; set; }
[DataMember(Name = "LastName")]
public string LastName { get; set; }
[DataMember(Name = "Mobile")]
public string Mobile { get; set; }
[DataMember(Name = "UserAddress")]
public Address UserAddress { get; set; }
}
2.运营合约
[OperationContract]
[WebInvoke(UriTemplate = "/RegisterUser", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST")]
Guid Register(NewUser col);
3.JS/Angular http post调用
var newUser = {};
newUser.Email = $scope.col.Email;
newUser.FirstName = $scope.col.FirstName;
newUser.LastName = $scope.col.LastName;
newUser.Mobile = $scope.col.Mobile;
newUser.CityId = $scope.col.UserAddress.CityId;
$http.post(API_URL + "/RegisterUser", { col: newUser }).success(function (response) {
if(response.status=="success" && !response.mailError){
$scope.register = false;
$scope.alert = {type:'success', msg:"You are successfully registered. Please check mail for the password. If you do not see the mail, check spams"};
}else if(response.mailError){
$scope.alert = {type:'warning', msg:'Unable to send mail! please try forgot password next time you need to login'};
}else{
$scope.alert = {type:'danger', msg:response.msg};
}
$scope.loading = false;
});
- 结果: 调用成功,调用Service中的相关Register函数。但是收到的 NewUser 对象的所有属性都设置为 NULL。
这些值在 JS 方面是正确的,因此在调用之间它的某些东西是不正确的。 任何指针?我的猜测是我遗漏了一些明显且非常小的东西,但目前似乎无法弄清楚。
【问题讨论】:
-
请忽略从 WCF 服务返回给 JS 的返回值,因为我正在纠正这些值。然而,核心问题是在请求部分收到 NULL。
标签: javascript c# angularjs wcf