PrepAway - Latest Free Exam Questions & Answers

You need to ensure that all clients calling GetMessage will retrieve the updated string if the message is upda

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()> 02 Public Interface ITeamMessageService 03 04
<OperationContract()> 05 Function GetMessage() As String 06 07 <OperationContract()>
08 Sub PutMessage(ByVal message As String) 09 End Interface The code for the service
class is as follows. 10 Public Class TeamMessageService 11 Implements
ITeamMessageService 12 13 Dim key As Guid = Guid.NewGuid() 14 Dim message As
String = “Today s Message” 15 16 Public Function GetMessage() As String _ 17
Implements ITeamMessageService.GetMessage 18 19 Return String.Format(“Message:{0}.
Key:{1}”, message, key) 20 End Function 21 22 Public Sub PutMessage(ByVal message As
String) _ 23 Implements ITeamMessageService.PutMessage 24 25 Me.message =
message 26 End Sub 27 28 End Class The service is self-hosted. The hosting code is as
follows. 29 Dim host As ServiceHost = New ServiceHost(GetType(TeamMessageService))
30 Dim binding As BasicHttpBinding = New

BasicHttpBinding(BasicHttpSecurityMode.None) 31 host.AddServiceEndpoint(
“MyApplication.ITeamMessageService”, binding, “http://localhost:12345”) 32 host.Open()
You need to ensure that all clients calling GetMessage will retrieve the updated string if the
message is updated by any client calling PutMessage. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Add the following attribute to the TeamMessageService class, before line 10002E
<ServiceBehavior(InstanceContextMode:= InstanceContextMode.PerSession)>

B.
Then change the implementation of PutMessage in lines 22-26 to the following. Public
Sub PutMessage(ByVal message As String) _ Implements
ITeamMessageService.PutMessage TeamMessageService.message = message End Sub

C.
Pass a service instance to the instancing code in line 29, as follows. Dim host As
ServiceHost = New ServiceHost(New TeamMessageService())

D.
Add the following attribute to the TeamMessageService class, before line 10.
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single)>

E.
Redefine the message string in line 14, as follows. Shared message As String = “Today s
Message”


Leave a Reply