Click here to Skip to main content
15,881,650 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am new to ASP.NET Webservice. I am currently using VS2010 Web Developer Express. I am unable to the following. Please help where I am doing wrong.

using System;
using System.Collections.Generic;

using System.Web;
using System.Web.Services;

namespace Session_Test_Service
{
    /// <summary>
    /// Summary description for Test_Session_Service
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/service")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Test_Session_Service : System.Web.Services.WebService
    {

        [WebMethod(EnableSession = true)]
        public int Calculate(int FirstNumber, int SecondNumber)
        {
             List<string> calculations;

            if (Session["CALCULATIONS"] == null)
            {
                calculations = new List<string>;
            }
            else
            {
                calculations = (List<string>)Session["CALCULATIONS"];
            }
            string strRecentCalcuulation = FirstNumber.ToString()+ "+" +SecondNumber.ToString()+ " = " + (FirstNumber+SecondNumber).ToString();
            calculations.Add(strRecentCalcuulation);

            return FirstNumber+SecondNumber;
        }

        [WebMethod(EnableSession = true)]
        public List<string> GetCalculation()
        {
            if (Session["CALCULATIONS"] == null)
            {
                List<string> calculations = new List<string>;
                calculations.Add("You have not performed any calculations");
                return calculations;
            }
            else
            {
                return (List<string>)Session["CALCULATIONS"];
            }

        }
    }
}


Thanks in advance!!
Posted
Comments
Kornfeld Eliyahu Peter 26-Jan-14 10:43am    
First of all this - calculations = new List<string>; - does not compile. "A new expression requires (), [], or {} after type".
Fix it than tell us what the real problem...
thatraja 27-Jan-14 3:25am    
what's the error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900