Solved

Using session variable in webs Service using c#

Posted on 2014-03-25
2
319 Views
Last Modified: 2014-07-09
Hi,

I have a web service in which I want to use a session variable that I'll create to be used in the web service.

The variable is called ListOfParts which I want to log to an event log in the web service.

Can I create a session variable to be used in the web service which would be created after creating the ListOfParts which is a count of parts which is done in another class.

What and how do I enable using session variables in the web service in order to see the session variable ListOfParts.  How do I create that session variable?

I am using c# for this effort.

Thanks in advance,

Isaac
webserviceVariables.zip
0
Comment
Question by:TechIsaac
2 Comments
 
LVL 7

Accepted Solution

by:
Raghu Mutalikdesai earned 500 total points
ID: 40138963
In any .NET web application, there are few implicit Context objects available by default. You don't have to enable these. The objects are Server, Application, Request, Response and Session.

You can store any type of data in a Session variable. In C#, it is as simple as:
List<String> nameList = GetList();
Session["MyVar"] = nameList;

And to retrieve it:
List<String> nameList = (List<String>)Session["MyVar"]

Of course, you need to do some sanity checking of the data before you use it after retrieving it from Session.

And note that this code is possible directly in a code-behind file (aspx.cs). If you have a class library code (a simple cs file), then you might have to include necessary namespaces and add System.Web as reference to that class library.

HTH
0
 

Author Comment

by:TechIsaac
ID: 40186924
Thanks much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now