WCF服务客户端错误“XXX的最佳重载方法匹配有一些无效的参数”

时间:2013-11-21 13:22:41

标签: c# wpf wcf mvvm wcfserviceclient

您好我正在创建一个MVVM应用程序,我将我的数据库链接到项目,我有一个WCF服务添加到我的项目,我有一个服务引用创建,所以我可以从我的应用程序添加到我的数据库的新数据。

在我的应用程序视图模型中,我有一个命令可以将新用户保存到数据库中,并在该C#文件中创建服务客户端的新实例,然后该命令存储在服务文件中。但是,当我使用我的服务调用此命令时,我收到错误:“XXX的最佳重载方法匹配有一些无效的参数”,我无法弄清楚为什么因为一切似乎都正确添加。

以下是我的一些代码,向您展示我在viewmodel中到目前为止所拥有的内容,并且在此行下我得到了错误(_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;
     }

然后在service.svc.cs中我有:

    [OperationContract]
    public int SaveNewUser(User user)
    {
        using (var context = new SolutionEntities())
        {
            context.Users.AddObject(user);
            context.SaveChanges();
            return user.UserID;               

        }
    }

User类看起来像:

       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();

希望有人能看出我的问题所在,谢谢。

0 个答案:

没有答案