This is my first time working with web services so im very newb to it but i have to learn it for work. Anyway, following a tut and I'm using Visual studio 2015. I've ran into a issue where my session is not saving the data. I have already updated the web
service multipal times and I've tested it in the webservice its self. The web service appears to work. Something is wrong between the web service and the web form. The session data is not saving and its not displaying in the grid view.
Here is the web service code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebServicesDemo
{
/// <summary>
/// Summary description for CalculatorWebService
/// </summary>
[WebService(Namespace = "http://www.holmes-abel.net/web_services")]
[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 CalculatorWebService : System.Web.Services.WebService
{
[WebMethod(EnableSession = true)]
public int Add(int Number_1, int Number_2)
{
try
{
List<string> calculations;
if(Session["_Calculations"] == null)
{
calculations = new List<string>();
}
else
{
calculations = (List<string>)Session["_Calculations"];
}
string CalcHistory = Number_1.ToString() + " + " + Number_2.ToString() + " = " + (Number_1 + Number_2).ToString();
int result = (Number_1 + Number_2);
calculations.Add(CalcHistory);
Session["_Calculations"] = calculations;
return result;
}
catch(Exception ex)
{
return 0;
}
}
[WebMethod(EnableSession = true)]
public List<string> GetCalculations()
{
try
{
List<string> Calculations = new List<string>();
if (Session["_Calculations"] == null)
{
Calculations.Add("You Performed Any Calculations Yet!");
}
else
{
Calculations = (List<string>)Session["_Calculations"];
}
return Calculations;
}
catch (Exception ex)
{
List<string> Calculations = new List<string>();
Calculations.Add(ex.ToString());
return Calculations;
}
}
}
}
Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebServicesDemo
{
public partial class Calculator : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAdd_Click(object sender, EventArgs e)
{
try
{
CalculatorService.CalculatorWebServiceSoapClient client = new CalculatorService.CalculatorWebServiceSoapClient();
string Result = Convert.ToString(client.Add(Convert.ToInt32(tbNumber1.Text), Convert.ToInt32(tbNumber2.Text)));
lblResult.Text = Result;
grdCalculations.DataSource = client.GetCalculations();
grdCalculations.DataBind();
}
catch(Exception ex)
{
}
}
}
}
Member
19 Points
180 Posts
Web Service Session not working
Jan 27, 2017 07:46 PM|UOKSoftware|LINK
This is my first time working with web services so im very newb to it but i have to learn it for work. Anyway, following a tut and I'm using Visual studio 2015. I've ran into a issue where my session is not saving the data. I have already updated the web service multipal times and I've tested it in the webservice its self. The web service appears to work. Something is wrong between the web service and the web form. The session data is not saving and its not displaying in the grid view.
Here is the web service code:
Code Behind:
Html:
web config file:
Member
19 Points
180 Posts
Re: Web Service Session not working
Jan 27, 2017 07:52 PM|UOKSoftware|LINK
I fixed it in the web config. using this:
I'm still not seeing it popup in the grid view though. Gridview should except a list right or do I need to use a listbox?
Member
19 Points
180 Posts
Re: Web Service Session not working
Jan 27, 2017 07:56 PM|UOKSoftware|LINK
Fixed it i had to set the gridview to auto generate columns. lame ... Thanks everyone