[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using session variable in webs Service using c#

Posted on 2014-03-25
2
Medium Priority
?
362 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

829 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