Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 496645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:42:20+00:00 2026-05-13T05:42:20+00:00

I’m having an issue with ASP.NET’s session variables and a web service proxy object.

  • 0

I’m having an issue with ASP.NET’s session variables and a web service proxy object. I can access any data I create inside the actual .asmx file, but adding data “Through” the session variable results in absolutely nothing happening.

My goal is quite simple, I want to create an “Almost Shopping cart”. The customer enters a title into this text box, and it’s sent to the Web Service. The web service is called in the masterpage, and it grabs an array list full of the “titles” that the customer is requesting.

The data is visible in a drop down box, and a label that stores the total cost of all the items (I’m not worried about the cost at the moment).

The issue is, anytime I call a web service method, absolutely nothing happens.

The Code in question:

Basket.asmx

public class basket  : System.Web.Services.WebService {

ArrayList reservations = new ArrayList();
double total = 0;

public basket()
{
    reservations.Add("Extreme Test Data");
    reservations.Add("Moar Test Data");
}

[WebMethod]
public string[] getReservations()
{
    //This may be part of the issue, still not sure.

    return (string[])reservations.ToArray(typeof( string));
}
[WebMethod]
public string toString()
{
    return reservations[reservations.Count - 1].ToString();
}


[WebMethod]
public double getTotal()
{
    return total;
}

[WebMethod]
public void addCost(double price)
{
    total = total + price;
}

[WebMethod]

public void addReservation(String title)
{

    reservations.Add(title);

}
[WebMethod]
public void removeReservation(string title)
{
}
[WebMethod]
public int getLength()
{
    return reservations.Count;
}

Global.asax

    void Session_Start(object sender, EventArgs e) 
{
    // Code that runs when a new session is started
    localhost.basket proxy = new localhost.basket();
    Session["reservations"] = proxy;
}

(Everything else in global.asax is default)

Masterpage

This is the only relevant code in the masterpage, It calls the web service through the session variable.

    protected void Page_Load(object sender, EventArgs e)
{

    localhost.basket proxy = (localhost.basket)Session["reservations"];

        lblTotal.Text = proxy.getTotal().ToString("c");
        string[] res = proxy.getReservations();
        ddReservations.DataSource = res;
        ddReservations.DataBind();
        proxy.addReservation("Half Life 2");
}

Reservations.aspx

This page submits the actual “new” data to the web service. I’ve cut out a lot of this (It’s a group project, so there’s a lot of code I didn’t write).

protected void Page_Load(object sender, EventArgs e)
{
    proxy = (localhost.basket)Session["reservations"];
    Response.Write(proxy.toString() + "Count: " + proxy.getLength());

}

  protected void cmdSubmit_Click(object sender, EventArgs e)
{
    proxy.addReservation(txtGameTitle.Text);        
    proxy.addCost(39.99);
}

What does work: The default test values I entered in the ASMX, they load fine into the textbox.

So in short, can I use a web service proxy object in a session variable? If not, whats the best way to “share” this object?

Also: I’m using VS2005.

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:42:21+00:00Added an answer on May 13, 2026 at 5:42 am

    Every web service call occurs on a different instance of the web service class. Your reservations variable cannot be used to maintain state between calls, since it’s an instance variable.

    You’re better off making your service be stateless. However, for a case like this, you should store the shopping cart into a database. That way, the cart won’t be lost on a system failure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.