Solved

Using session variable in webs Service using c#

Posted on 2014-03-25
2
317 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

      Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

743 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

10 Experts available now in Live!

Get 1:1 Help Now