Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Using Session from a Windows App throgh a WebService

Reply
Thread Tools

Using Session from a Windows App throgh a WebService

 
 
Per Loevgren
Guest
Posts: n/a
 
      06-28-2004
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
 
Reply With Quote
 
 
 
 
Kondratyev Denis
Guest
Posts: n/a
 
      06-28-2004
Show code for this.

> 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



 
Reply With Quote
 
 
 
 
Per Loevgren
Guest
Posts: n/a
 
      06-29-2004
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
 
Reply With Quote
 
Per Loevgren
Guest
Posts: n/a
 
      06-29-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cut-throgh packet switching madratz Cisco 2 06-06-2007 01:33 AM
Error connection using webservice locally (3 webservice in balanci Roberto Giorgetti ASP .Net Web Services 0 06-13-2006 06:40 PM
Retrieve session from different app domain using Out-Proc SQL session irfangani@gmail.com ASP .Net 1 05-19-2006 12:08 PM
Windows app using webservice sessions and cookies Joshua Moore ASP .Net Web Services 3 01-19-2006 06:51 PM
Problems launching legacy windows app from webservice Odin Jensen ASP .Net Web Services 1 09-19-2003 02:54 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57