Solved

Using session variable in webs Service using c#

Posted on 2014-03-25
2
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Storing Data in multiple Countries 5 52
Recursive Folder Upload via Web 5 86
RD Web 8 128
Website authentication - asp.net 3 93
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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.

733 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