473,395 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cookies and web services

I posted this in the WinForms forum, and didn't get an answer yet. Come
to think of it, I am sure some of you guys were confronted to that
problem too, because the same scenario can happen in ASP.NET too
(server-side of course). Allow me to post here too:

Hi,

I got a problem when I try to connect to a stateful web service using a
Windows Forms application (actually, a WPF application, but it's the same).

Simplified code:

SERVER:

[WebService( Namespace = "http://www.galasoft-lb.ch/" )]
[WebServiceBinding( ConformsTo = WsiProfiles.BasicProfile1_1 )]
[ToolboxItem( false )]
public class Service1 : System.Web.Services.WebService
{
[WebMethod( EnableSession=true )]
public string GetSessionId()
{
return Session.SessionID;
}
}

CLIENT:

private Service1 m_oService = new Service1();

public Form1()
{
InitializeComponent();
m_oService.CookieContainer = new CookieContainer();
}

private void bnExecute_Click( object sender, EventArgs e )
{
try
{
DisplayResults( m_oService.GetSessionId(), false );
}
catch ( Exception ex )
{
DisplayResults( ex.Message, true );
}
}

Any idea what's causing the problem? The cookies are never set.

Thanks,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 9 '06 #1
3 2813
Hi Laurent,

Try moving the declaration of cookiecontainer into the private declarations
of your client

private Service1 m_oService = new Service1();
private CookieContainer myCookies = new CookieContainer();

and set that
public Form1()
{
InitializeComponent();
m_oService.CookieContainer = myCookies;
}

--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
"Laurent Bugnion" <ga*********@bluewin.chwrote in message
news:O8****************@TK2MSFTNGP02.phx.gbl...
>I posted this in the WinForms forum, and didn't get an answer yet. Come to
think of it, I am sure some of you guys were confronted to that problem
too, because the same scenario can happen in ASP.NET too (server-side of
course). Allow me to post here too:

Hi,

I got a problem when I try to connect to a stateful web service using a
Windows Forms application (actually, a WPF application, but it's the
same).

Simplified code:

SERVER:

[WebService( Namespace = "http://www.galasoft-lb.ch/" )]
[WebServiceBinding( ConformsTo = WsiProfiles.BasicProfile1_1 )]
[ToolboxItem( false )]
public class Service1 : System.Web.Services.WebService
{
[WebMethod( EnableSession=true )]
public string GetSessionId()
{
return Session.SessionID;
}
}

CLIENT:

private Service1 m_oService = new Service1();

public Form1()
{
InitializeComponent();
m_oService.CookieContainer = new CookieContainer();
}

private void bnExecute_Click( object sender, EventArgs e )
{
try
{
DisplayResults( m_oService.GetSessionId(), false );
}
catch ( Exception ex )
{
DisplayResults( ex.Message, true );
}
}

Any idea what's causing the problem? The cookies are never set.

Thanks,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Oct 9 '06 #2
Hi John,

John Timney (MVP) wrote:
Hi Laurent,

Try moving the declaration of cookiecontainer into the private declarations
of your client

private Service1 m_oService = new Service1();
private CookieContainer myCookies = new CookieContainer();

and set that
public Form1()
{
InitializeComponent();
m_oService.CookieContainer = myCookies;
}
Thanks for your reply. Actually, my client-side code was fine. Funnily
enough, after a looooong time spent looking for the error, I finally
(with the help of a colleague) found out what the problem was, and it
was in the server: When I created the Web service application, the
Global.asax handler was missing. This is the new default in ASP.NET 2.0
(in 1.1, the Global.asax was always present by default).

When the Global.asax is missing, the application runs fine, but without
any session management. Everything occurs as if a new Session started on
every request.

Actually, you can try deleting the Global.asax in a 1.1 Web service
application, and the same result can be observed: The SessionID is
different on every request.

Anyway, thanks for taking the time.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 10 '06 #3
Follow up:
http://geekswithblogs.net/lbugnion/a.../11/93737.aspx

Thanks,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: sd | last post by:
Hello: I have smart client app which needs to access a "forms authentication" protected website for certain functions. Thre credentials used to login to smart client are the same as the...
6
by: NWx | last post by:
Hi, How can I detect is cookies are enabled or not in client browser? Thanks?
1
by: Ted Bogucki | last post by:
using asp.net I can write out cookies using response.cookies and read cooies with request.cookies If I enable a firewall like zonealarm then the cookies wiill write out but the asp page will...
2
by: craigkenisston | last post by:
IExplorer cookies stubbornness. Hi, I'm testing how my asp.net application reacts with a browser that does not accept cookies. Tested it with Opera and Mozilla with cookies off, I can clearly...
9
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET...
3
by: David Thielen | last post by:
Hi; I need to keep a string in Session however this does not work if the user has cookies turned off. How can I work around this? -- thanks - dave david_at_windward_dot_net...
6
by: Eric | last post by:
I would like to read cookies in the client (WinForm App), which where sent by a server. I have set "ws.CookieContainer = New System.Net.CookieContainer()" in my client, before I call the...
1
by: Eric Layman | last post by:
This is how I clear all cookies/give cookies/detect cookies am i doing it the right way? Somehow or rather, i would hit an object cannot be instanisiated from null or something whenever it tries...
2
by: archana | last post by:
Hi all, I am developing one web service. I am not clear about some concept of web servic. I want to ask Do web service always support cookie-based session? or i can have session without...
2
by: dad107 | last post by:
Hi everyone. My web application wants to take advantage of an encrypted authentication cookie that's provided by another application on the same server. The cookie is visible on the client side,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.