Hi I am creating an MVVM application and I have my database linked up to the project, I have a WCF service added to my project and I have a service reference created so I can add new data from my application to my database.
In my application viewmodel I have a command that saves a new user to the database and I create a new instance of my service client within that C# file, and then the command is stored within the service file. However, when I go to call this command using my service I get the error: "the best overloaded method match for XXX has some invalid arguments" and I can't figure out why because everything seems to be added correctly.
Here is some of my code to show you what I have so far in the viewmodel, and it is under this line I get the error (_serviceClient.SaveNewUser(newUser);) :
public RelayCommand AddUserCommand { get; private set; }
private ServiceClient _serviceClient;
public AddUserViewModel()
{
_serviceClient = new ServiceClient();
AddUserCommand = new RelayCommand(() => ExecuteAddUserCommand());
}
private void ExecuteAddUserCommand()
{
User newUser = new User();
newUser.FirstName = this.FirstName;
newUser.LastName = this.LastName;
newUser.ContactNumber = this.ContactNumber;
newUser.Email = this.Email;
//service call
int userID = _serviceClient.SaveNewUser(newUser);
newUser.UserID = userID;
}
Then in the service.svc.cs I have:
[OperationContract]
public int SaveNewUser(User user)
{
using (var context = new SolutionEntities())
{
context.Users.AddObject(user);
context.SaveChanges();
return user.UserID;
}
}
The User class looks like:
public partial class Client : EntityObject
{
public static Client CreateClient(global::System.Int32 userID, global::System.String firstName, global::System.String lastName, global::System.String contactNumber)
{
User user = new User();
user .UserID = userID;
user .FirstName = firstName;
user .LastName = lastName;
user .ContactNumber = contactNumber;
return user;
}
public global::System.Int32 UserID
{
get
{
return _UserID;
}
set
{
if (_UserID!= value)
{
OnUserIDChanging(value);
ReportPropertyChanging("UserID");
_UserID= StructuralObject.SetValidValue(value, "UserID");
ReportPropertyChanged("UserID");
OnUserIDChanged();
}
}
}
private global::System.Int32 _UserID;
partial void OnUserIDChanging(global::System.Int32 value);
partial void OnUserIDChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String FirstName
{
get
{
return _FirstName;
}
set
{
OnFirstNameChanging(value);
ReportPropertyChanging("FirstName");
_FirstName = StructuralObject.SetValidValue(value, false, "FirstName");
ReportPropertyChanged("FirstName");
OnFirstNameChanged();
}
}
private global::System.String _FirstName;
partial void OnFirstNameChanging(global::System.String value);
partial void OnFirstNameChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String LastName
{
get
{
return _LastName;
}
set
{
OnLastNameChanging(value);
ReportPropertyChanging("LastName");
_LastName = StructuralObject.SetValidValue(value, false, "LastName");
ReportPropertyChanged("LastName");
OnLastNameChanged();
}
}
private global::System.String _LastName;
partial void OnLastNameChanging(global::System.String value);
partial void OnLastNameChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String ContactNumber
{
get
{
return _ContactNumber;
}
set
{
OnContactNumberChanging(value);
ReportPropertyChanging("ContactNumber");
_ContactNumber = StructuralObject.SetValidValue(value, false, "ContactNumber");
ReportPropertyChanged("ContactNumber");
OnContactNumberChanged();
}
}
private global::System.String _ContactNumber;
partial void OnContactNumberChanging(global::System.String value);
partial void OnContactNumberChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String Email
{
get
{
return _Email;
}
set
{
OnEmailChanging(value);
ReportPropertyChanging("Email");
_Email = StructuralObject.SetValidValue(value, true, "Email");
ReportPropertyChanged("Email");
OnEmailChanged();
}
}
private global::System.String _Email;
partial void OnEmailChanging(global::System.String value);
partial void OnEmailChanged();
Hopefully someone can see where my problem lies, thanks.