Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WCF
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.
 
[Serializable]
    [DataContract]
    public class LoginUser
    {
        [DataMember]
        public string UserName { get; set; }
        [DataMember]
        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?
Posted 24-Aug-12 4:01am
digimanus26.5K
Edited 24-Aug-12 4:05am
v3
Comments
Himanshu Yadav at 28-Aug-12 1:24am
   
Update yr service by right clicking on service.and u will get the property.
digimanus at 28-Aug-12 15:00pm
   
thank you, it works now
nile.black at 28-Aug-12 21:10pm
   
thanks, it's my problem too.
digimanus at 28-Aug-12 15:18pm
   
thanks for your information. Will read it

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 = "****" };
proxy.set_UserLogin(lu);
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.
  Permalink  
v2
Comments
RaisKazi at 28-Aug-12 16:37pm
   
Nice troubleshoot and solution. My 5!
Wonde Tadesse at 28-Aug-12 21:19pm
   
5+

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



Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid