How to keep session alive between two calls to a web service in a c# application?

后端 未结 3 802
青春惊慌失措
青春惊慌失措 2020-12-19 15:06

This is quite straight forward.
I\'m calling a web-service (.asmx, with session enabled) from a c# application.

I want each call to be with the same session ke

相关标签:
3条回答
  • 2020-12-19 15:19

    From first call, look after ASP.NET_SessionId value in response, this is session Id by default.

    Then add it to next call (see below):

    http://support.microsoft.com/?kbid=899918

    0 讨论(0)
  • 2020-12-19 15:24

    If I understand the question correctly, I believe you'll need to get the session cookie from the response (the first time you call the web service) and add it to the request in the subsequent calls.

    Edit:

    Using CookieContainer is the correct way but be aware that it's null by default so you'll have to to assign a CookieContainer object to the property before making the request (see the example code in the MSDN's article).

    As to the cookie name, the default name for ASP.NET session cookie is ASP.NET_SessionId, but the name can be different as it can be changed in web.config, or they might not be using ASP.NET sessions (their own implementation for example), so you'll have to check the cookies you get from the domain of that application (You can use an HTTP sniffer like Fiddler, or more easily if you're using FireFox or Chrome, you can check the names and contents of the cookies you get from that domain in the options dialog box).

    0 讨论(0)
  • 2020-12-19 15:29

    There is a good discussion of using ASP.NET session state with web services on MSDN here:

    http://msdn.microsoft.com/en-us/library/aa480509.aspx

    0 讨论(0)
提交回复
热议问题