Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i want to pass session variable from my asp.net website to WCF service can you help me i have doen from service side but not able to pass value from aspx page.
Can u help me plzzz. Its really very urgent.

Code of WCF Service

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
   public class Service1 : IService1
   {
       //bool boolValue = true;
       //string stringValue = "Hello ";
       public string Greet(string words)
       {
           return GreetInternal(words);
       }
       public string Greet2(string words)
       {
           return GreetInternal(words);
       }
       string GreetInternal(string words)
       {
           MySessionState state = (MySessionState)HttpContext.Current.Session["MySessionState"];
           if (state == null) {
               state = new MySessionState();
               HttpContext.Current.Session["MySessionState"] = state;
           }
           int counter = state.Touch();
           return string.Format("[Session '{0}'] You said: {1} (counter: {2})", HttpContext.Current.Session.SessionID, words, counter);
       }

   }
   class MySessionState
   {
       int counter;
       public MySessionState() { }
       public int Counter { get { return this.counter; } }
       public int Touch() { return Interlocked.Increment(ref this.counter); }
   }


Note to OP: Please do not use text speak. Also, it may be urgent for you, but not for us. So try avoiding that while posting.
Posted
Updated 2-Feb-11 10:00am
v2

1 solution

There are three things to consider while sharing sessions:

1. aspNetCompatibilityEnabled = true
2.[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
3. allowCookies = true

I think that's enough hint for you to proceed.

BTW, I personally do not like kind of design. I would have used following approach:

Your session object should made a data contract or a message contract and then passed on to service. That IMHO is cleaner and decoupled way of doing things.
 
Share this answer
 

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