Click here to Skip to main content
15,920,513 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello everyone,

first of all I am new to WCF. That is the basic problem to my problem, I know!

I want to make a call to my WCF service and in that works OK.
What I want is that each call to the Service contains a filled LoginUser object.

    public class LoginUser
        public string UserName { get; set; }
        public string Password { get; set; }

In my Interface I state:
BLL.LoginUser LoginUser { [OperationContract] get; [OperationContract]set; }

In my service class I have:
public BLL.LoginUser LoginUser { [OperationBehavior]get; [OperationBehavior]set; }

In the client I get 2 methods (get_LoginUser() ans set_LoginUser()) but I want to see a property.

I tested with these methods and I can set the values for UserName and Password with the method, but when calling the next method my Loginuser object is NULL again.

That is why I want to have a property to set and that in the next call the LoginUser object still has the data.

I do not want to add the object of LoginUser as a parameter in the WCF call or is that the only option?

I instantiate my call to the service as:
srPersonal.IStatistics sc = new srPersonal.StatisticsClient();

I then want to do a
srPersonal.BLL.LoginUser lu = new srPersonal.BLL.LoginUser();
lu.UserName = "hi";
lu.Password = "*****";
sc.LoginUser = lu;
var result = sc.GetMyData();

What do I have to change?
Updated 24-Aug-12 4:05am
Himanshu Yadav 28-Aug-12 1:24am    
Update yr service by right clicking on service.and u will get the property.
Herman<T>.Instance 28-Aug-12 15:00pm    
thank you, it works now 28-Aug-12 21:10pm    
thanks, it's my problem too.
Herman<T>.Instance 28-Aug-12 15:18pm    
thanks for your information. Will read it

1 solution

WCF don't allow properties on interfaces. The 'get' and 'set' will work as a methods, but not as a property.

In your case, this will work:
ServiceReference1.IService1 proxy = new ServiceReference1.Service1Client();
ServiceReference1.LoginUser lu =
    new ServiceReference1.LoginUser() { UserName = "hi", Password = "****" };
var result = proxy.get_UserLogin();

You could do a regular basic authentication. It is some work, but it is a better way to handle user name and passwords.
Share this answer
RaisKazi 28-Aug-12 16:37pm    
Nice troubleshoot and solution. My 5!
Wonde Tadesse 28-Aug-12 21:19pm    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900