I want to set and get information in a Session variable on an IIS
application (ASP.NET website) from a Windows App.
I use webservices to communicate with the IIS app. and keep all calls
from the webservices in the same session.
I have deployed my webservices to the folder where the IIS app resides
and when I call to get the value of an Application variabel there are
no problems, but as soon as I call to get the value of a Session
variable I get an exception.
If i call the webservice from my ASP.NET app. there are no problems
with the session variable.
The Webservice looks as follows:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace StatusWS
{
public class GetStatus : System.Web.Services.WebService
{
public GetStatus()
{
//CODEGEN: This call is required by the ASP.NET Web Services
Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod (EnableSession=true)]
public string GetStatusApplication( string strSerialNo, string OTP )
{
string strStatus = Application["Status"] != null ?
Application["Status"].ToString() : "<No status found>";
return Server.HtmlEncode(strStatus);
}
[WebMethod (EnableSession=true)]
public string GetStatusSession( string strSerialNo, string OTP )
{
string strStatus = Session["Status"] != null ?
Session["Status"].ToString() : "<No status found>";
return Server.HtmlEncode(strStatus);
}
}
}
I have deployed it by copying the asmx file to the ASP.NET application
folder, and added a webreference to it in my windows app.
The windows app. calls like this:
private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = new StatusWS.GetStatus().GetStatusSession( "", "" );
}
private void button2_Click(object sender, System.EventArgs e)
{
textBox2.Text = new StatusWS.GetStatus().GetStatusApplication( "", ""
);
}
I have tried to set CookieContainer on my webservice object but that
didn't do any good.
Any ideas or thoughts are most welcome
Rgds.,
Per Loevgren
Kondratyev Denis - 28 Jun 2004 21:37 GMT
Show code for this.
> I have tried to set CookieContainer on my webservice object but that
> didn't do any good.
[quoted text clipped - 4 lines]
>
> Per Loevgren
Per Loevgren - 29 Jun 2004 10:52 GMT
I found the solution.
What I did wrong was to create a new CookieContainer for each call to
the webservice.
Instead I have create a private variable to hold the CookieContainer
and then only set this variable if its value is null.
i.e.:
private CookieContainer thisCookie;
private void button1_Click(object sender, System.EventArgs e)
{
StatusWS.GetStatus objWS = new StatusWS.GetStatus();
if ( thisCookie == null )
{
thisCookie = new CookieContainer();
}
objWS.CookieContainer = thisCookie;
textBox1.Text = objWS.GetStatusSession( "", "" );
}
Rgds.,
Per Loevgren
Per Loevgren - 29 Jun 2004 07:56 GMT
Some info i forgot in my previous post ...
The code that sets the CookieContainer is like this:
private void button1_Click(object sender, System.EventArgs e)
{
StatusWS.GetStatus objTest = new StatusWS.GetStatus();
objTest.CookieContainer = new CookieContainer();
textBox1.Text = objTest.GetStatusSession( "", "" );
}
The exception thrown is:
An unhandled exception of type
'System.Web.Services.Protocols.SoapException' occurred in
system.web.services.dll
Additional information: System.Web.Services.Protocols.SoapException:
Server was unable to process request. --->
System.NullReferenceException: Object reference not set to an instance
of an object.
at StatusWS.GetStatus.GetStatusSession(String strSerialNo, String
OTP) in c:\inetpub\wwwroot\statusws\statusws.asmx.cs:line 64
--- End of inner exception stack trace ---
Rgds.,
Per Loevgren