You need to ensure that all clients calling GetMessage will retrieve the same string, even if the message is updated by clients calling PutMessage

A Windows Communication Foundation (WCF) solution uses the following contract to share
a message across its clients. (Line numbers are included for reference only.) 01
[ServiceContract] 02public interface ITeamMessageService 03{ 04 [OperationContract]
05string GetMessage0;n 06 07 [OperationContract] 08void PutMessage(string message);
09) The code for the service class is as follows 10 public class TeamMessageService:
ITeamMessageService 1 1{ 12Guid key = GuicLNewGuidO; 1 3string message = “Today’s
Message”: 1 4public string GetMessage() i5{ 16 return stringFormat(”Message:{0} Key:{1}”,
message, Key); 1n 18 1 9public void PutMessage(string message) 20{ 2lthismessage =
message; 22} 23) The senvice is self-hosted. The hosting code is as follows. 24
ServiceHost host = 25BasicHttpBinding binding = new

BasicHttpBinding(BasicHttpSecuntyMode.None): 26 host AddServiceEndpoint(
HMyApplication lTeamMessageService, binding, “http:/Ilocalhost: 12345w); 27 host Open0;)
You need to ensure that all clients calling GetMessage will retrieve the same string, even if
the message is updated by clients calling PutMessage. What should you do?

A Windows Communication Foundation (WCF) solution uses the following contract to share
a message across its clients. (Line numbers are included for reference only.) 01
[ServiceContract] 02public interface ITeamMessageService 03{ 04 [OperationContract]
05string GetMessage0;n 06 07 [OperationContract] 08void PutMessage(string message);
09) The code for the service class is as follows 10 public class TeamMessageService:
ITeamMessageService 1 1{ 12Guid key = GuicLNewGuidO; 1 3string message = “Today’s
Message”: 1 4public string GetMessage() i5{ 16 return stringFormat(”Message:{0} Key:{1}”,
message, Key); 1n 18 1 9public void PutMessage(string message) 20{ 2lthismessage =
message; 22} 23) The senvice is self-hosted. The hosting code is as follows. 24
ServiceHost host = 25BasicHttpBinding binding = new

BasicHttpBinding(BasicHttpSecuntyMode.None): 26 host AddServiceEndpoint(
HMyApplication lTeamMessageService, binding, “http:/Ilocalhost: 12345w); 27 host Open0;)
You need to ensure that all clients calling GetMessage will retrieve the same string, even if
the message is updated by clients calling PutMessage. What should you do?

A.
Add the following attribute to the TeamMessageService class, before line 10.
[ServiceBehavior(lnstanceContextMode = lnstanceContextMode. Single)]

B.
Add the following attribute to the TeamMessageService class, before line 10.
[ServiceBehavior(lnstanceContextMode = lnstanceContextModePerSession)J Then change
the binding definition on the service at line 25, and on the client to the following
WSHttpBinding binding new WSHttpBinding(SecurityModeNone); binding ReliableSession.
Enabled true;

C.
Pass a service instance to the instancing code in line 24, as follows. ServiceHost host =
new ServiceHost(new TeamMessageServiceO);

D.
Redefine the message string in line 13, as follows static string message = ‘Today’s
Message”: Then change the implementation of PutMessage in lines 19-22 to the following
public void PutMessage(string message) { TeamMessageServicemessage message, }



Leave a Reply 0

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