Reputation: 28692
How does webservice maintain session when client is windows/Console app?
Upvotes: 3
Views: 685
Reputation: 3611
Here is some sample code if someone is interested.
class Program
{
static void Main(string[] args)
{
CookieContainer session = new CookieContainer();
HttpWebRequest httpSomeRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/someURL");
httpSomeRequest.CookieContainer = session;
httpSomeRequest.GetResponse();
HttpWebRequest httpSomeOtherRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/someOtherURL");
httpSomeOtherRequest.CookieContainer = session;
httpSomeOtherRequest.GetResponse();
}
}
We just need to make sure that every HttpWebRequest
made, uses the same CookieContainer
instance.
Upvotes: 0
Reputation: 5439
Under the covers, the C# WebClient is storing the cookie given to it by the web service.
Upvotes: 2
Reputation: 888283
Using cookies.
When you send HTTP requests, make sure to include a CookieContainer
. (assuming you're using HttpWebRequest
)
Upvotes: 2