Below are the code snippets:
1. The intricate object:
[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. The Operation contract:
[OperationContract]
[WebInvoke(UriTemplate = "/RegisterUser", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST")]
Guid Register(NewUser col);
3. The JS/Angular HTTP POST call:
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;
});
- The Result: The call is successful and the related Register function in the Service is called. However, the NewUser object received has all properties set to NULL.
The values are correct from the JavaScript side, so it seems like there might be a small missing detail between the calls. Any suggestions? My hunch is that I am overlooking something simple but can't seem to pinpoint it at the moment.