What should you do to ensure that when the IncrementSession5Times method is run, the following output is displayed?

A Console Application calls a Web service named SessionStateService five times, sequentially.
The IncrementSessionCounter Web service method increments and returns an integer value that is held in a cookie.

(Line numbers are included for reference only.)
01 void IncrementSession5Times() {
02 SessionStateService service = null;
03 …
04 for (int i = 0; i < 5; i++) {
05 …
06 Console.WriteLine("Loop Pass {0} – result = {1}",
07 i,
08 service.IncrementSessionCounter());
09 }
10 }

You need to ensure that when the IncrementSession5Times method is run, the following output is displayed.

Loop Pass 0 – result = 1
Loop Pass 1 – result = 2
Loop Pass 2 – result = 3
Loop Pass 3 – result = 4
Loop Pass 4 – result = 5

What should you do?

A Console Application calls a Web service named SessionStateService five times, sequentially.
The IncrementSessionCounter Web service method increments and returns an integer value that is held in a cookie.

(Line numbers are included for reference only.)
01 void IncrementSession5Times() {
02 SessionStateService service = null;
03 …
04 for (int i = 0; i < 5; i++) {
05 …
06 Console.WriteLine(“Loop Pass {0} – result = {1}”,
07 i,
08 service.IncrementSessionCounter());
09 }
10 }

You need to ensure that when the IncrementSession5Times method is run, the following output is displayed.

Loop Pass 0 – result = 1
Loop Pass 1 – result = 2
Loop Pass 2 – result = 3
Loop Pass 3 – result = 4
Loop Pass 4 – result = 5

What should you do?

A.
Replace line 03 with the following code.
CookieContainer cookies = new CookieContainer();
Replace line 05 with the following code.
SessionStateService service = new SessionStateService();
service.CookieContainer = cookies;

B.
Replace line 03 with the following code.
SessionStateService service = new SessionStateService();

C.
Replace line 05 with the following code.
SessionStateService service = new SessionStateService();
CookieContainer cookies = new CookieContainer();
service.CookieContainer = cookies;

D.
Replace line 03 with the following code.
CookieContainer cookies = new CookieContainer();
Replace line 05 with the following code.
SessionStateService service = new SessionStateService();
cookies.GetCookies(new Uri(service.Url));



Leave a Reply 0

Your email address will not be published. Required fields are marked *