2
My goal is to create three applications: in WCF, in ASP.NEW Web API and another in WPF.
My question is this::
It is normal, the data that we initialize on the client side namely (WPF) and that we pass to the service (WCF) come to null?
Example of my code - WPF
InitializeComponent();
_gestaoInformacao = new Gestao_InformacaoUsersClient();
newUser = new Utilizador { Username = "Joao" };
_gestaoInformacao.addNovoUtilizador(newUser);
WCF:
public void addNovoUtilizador(Utilizador newUser)
{
projectContext.Users.Add(newUser);
projectContext.SaveChanges();
}
User class:
public class Utilizador
{
[DataMember]
[Key]
private int id_utilizador;
[DataMember]
private String _username;
[DataMember]
public String Username
{
get { return _username; }
set
{
_username = value;
//OnPropertyChanged("Username");
}
}
[DataMember]
private String _password;
[DataMember]
public String Password
{
get { return _password; }
set
{
_password = value;
//OnPropertyChanged("Password");
}
}
}
The point here is that when I pass the Newuser from WPF to WCF and run the debug to see the information you pass, VS says all user data is null (at least the username should have data)
This data, is it normal to be null, or is something wrong? Maybe with Services settings.
This seems like a serialization problem. It was not clear in your example, but how you marked the class attributes User with
DataMember
, you also marked the class withDataContract
?– Ricardo Pontual
Yes, it is normal to pass null variables from the customer side to the service side.
– Oralista de Sistemas