Reputation: 4480
I have created a Silverlight enabled WCF Service which looks like : I am using basicHttpBinding
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SLWebService
{
[OperationContract]
public string Login(string username, string password)
{
//Validate Username and Password against the Database.
// myctxt.Session["Uname"] = username;
HttpContext.Current.Session["username"] = username ;
return username;
}
[OperationContract]
public string ReturnUser()
{
return (string)HttpContext.Current.Session["username"];
}
}
}
The problem i am facing is i am getting username value is null everytime. I am consuming this WCF Service in Silverlight Client which looks like :
Page.xaml.cs:
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
SessionService.SLWebServiceClient client = new SessionService.SLWebServiceClient();
client.LoginAsync(txtuser.Text, txtpassword.Password);
NavigateRequest(1);
}
Welcome.xaml.cs
void Welcome_Loaded(object sender, RoutedEventArgs e)
{
SessionService.SLWebServiceClient client = new SessionService.SLWebServiceClient();
client.ReturnUserCompleted += new EventHandler<SessionService.ReturnUserCompletedEventArgs>(client_ReturnUserCompleted);
client.ReturnUserAsync();
}
void client_ReturnUserCompleted(object sender, SessionService.ReturnUserCompletedEventArgs e)
{
txtusername.Text = e.Result;
}
I am creating a Login Page(Page.xaml) ans entering Userid and password then it redirects to Welcome Page which welcome the current user but my service is not returning the username the session is null.
Thanks.
Upvotes: 0
Views: 633
Reputation: 8233
Add [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
above " public class SLWebService"
Upvotes: 2