Solved

Using session variable in webs Service using c#

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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

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 …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
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…

718 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