Search code examples
c#.netwcfsoapservice

Cannot pass the second parameter to the WCF service with two parameters


I'm new to WCF service applications. I'm following a tutorial. There I'm trying to pass a user name and a password and get the user object returned in that particular object if the username and the password matches.

in my App_code folder I have following class called Login.cs

public class Login
    {
        WindsForBusinessEntities001 newLogin = new WindsForBusinessEntities001();
        private string vusername;
        private string vpassword;

        public string UserName
        {
            get { return vusername; }
            set { vusername = value; }
        }
        public string Password
        {
            get { return vpassword; }
            set { vpassword = value; }
        }
        public string UserLogin()
        {
            var login = (from mstUser in newLogin.mstUsers where mstUser.userName == vusername && mstUser.password == vpassword select mstUser).Count() > 0;
            if (login)
            {
                return "1";
            }
            else return "0";
        }
    }

Here I have used an entity framework model object. In this I'm checking the username and password with a matching record in the database and return a string 1 if that particular user exists.

Following code segment is my Iservice1.cs class in my project.

[ServiceContract]
    public interface Iservice1
    {
        [OperationContract]
        string  UserLogin(vlogin login);
    }
    [DataContract]
    public class vlogin
    {
        private string vusername;
        private string vpassword;
        [DataMember]
        public string UserName
        {
            get
            {
                return vusername;
            }
            set
            {
                vusername = value;
            }
        }
        public string Password
        {
            get
            {
                return vpassword;
            }
            set
            {
                vpassword = value;
            }
        }
    }

This is my Service1.svc.cs file code segment.

public class Service1 : Iservice1 { public string UserLogin(vlogin login) { Login vlogin = new Login(); vlogin.UserName = login.UserName; vlogin.Password = login.Password; return vlogin.UserLogin(); } }

The problem I'm facing here is that, when I try to execute it only accepts my username only. It doesn't accept my password. The password cannot be given as an input. It only accepts one input. Therefore when executing this always it returns 0 only as it doesn't have a matching password.

enter image description here

enter image description here

What is the incorrect step that I'm following here? What should I do to pass the password in this?


Solution

  • enter image description here

    Password is not a [DataMemeber], each attribute shall be a DataMember of a DataContract class. DataContract defines it as a service that shall serve the purpose of getting or setting the data so the attributes of DataContract shall be DataMember