.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> WCF >> Post New QuestionBookmark and Share Subscribe to Forum

how to use sessions in wcf?how many types of sessions and session modes in wcf?

Posted By: divs99     Posted Date: May 27, 2012    Points:5   Category :WCF

i want replies for the given questions?

1.how many types of sessions and session modes in wcf?
2.which session mode is used at which case in wcf?( at which case we have to use?wht is its use and purpose?)
3.how to use sessions in wcf?
4.pls let me know when this session modes use in which case?
a.Sessionful binding b.SessionMode service contract c.InstanceContextMode service behavior
5.i decalred asp.net session variable and how to retrieve tht session varaible in wcf ?
HttpContext.Current.Session["test"] = "test";-------------storing data in session variable in asp.net

how to retrieve above session varaible in wcf?

6.see my sample code given below :

pls go through my below code and pls let me know y sessions are becoming null while passing asp.net variable to wcf service...................

the code which i have given below doesnt work for me .....iam getting null value in HttpContext.Current.Session while passing asp.net session variable to wcf service..

even i changed confile file as


<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/></system.serviceModel>...
service contract file :

[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples", SessionMode = SessionMode.Required)]

public interface IService3



classCustomer getCustomer(int intCustomer);



public class classCustomer


private string _strCustomer;

private string _strCustomerCode;

private string _strCustomerName;


public string Customer


get { return _strCustomer; }

set { _strCustomer = value; }



public string CustomerCode


get { return _strCustomerCode; }

set { _strCustomerCode = value; }



public string CustomerName


get { return _strCustomerName; }

set { _strCustomerName = value; }



public DataTable CustomerTable






Service class file(implementation file):


[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

public class Service3 : IService3


public classCustomer getCustomer(int intCustomer)


SqlConnection objConnection = new SqlConnection();

DataSet ObjDataset = new DataSet();

SqlDataAdapter objAdapater = new SqlDataAdapter();

SqlCommand objCommand = new SqlCommand("Select * from Customer where CustomerId=" + intCustomer.ToString());

objConnection.ConnectionString = System.Configuration.



objCommand.Connection = objConnection;

objAdapater.SelectCommand = objCommand;


classCustomer objCustomer = new classCustomer();

objCustomer.CustomerTable = ObjDataset.Tables[0];

object o = HttpContext.Current.Session["test"];...retrieving asp.net session variable getting null value in object


return objCustomer;



c# code file while consuming wcf:


ServiceReference4.Service3Client var4 = new ServiceReference4.Service3Client();

ServiceReference4.classCustomer cust = new ServiceReference4.classCustomer();

HttpContext.Current.Session["test"] = "test";-------------storing data in session variable in asp.net

cust = var4.getCustomer(1);

DataTable dt = new DataTable();

dt = cust.CustomerTable;

GridView1.DataSource = dt;



No response found. Be the first to respond this post
Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend