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
<ServiceContract0> 02PuElic Interface ITeamMessageService 03 04
<OperationContractO> 05Function GetMessage() As String 06 07 <OperationContract0>
08Sub PutMessage(Byval message As String) O9End Interface The code for the serAce
class is as follows. 10 Public Class TeamMessageService0 11 Implements
lTearmt4essageService 12 1 3Dim key As Guid = Guid.NewGuid() 1 4Dim message As
String = “Today’s Message’ 15 16PuUic Function GetMessage0As String – 1 7lmpements
lTearm*AessageServiceGetMessage 18 1 9Retun String. Fommat(”Message:{0) Key:{ 1}”,
message, key) 20End Function 21 22PubIic Sub PutMessage(ByV message As Stnng) –
23lmpements lTearrlessageService PutMessage 24 25Me message = message 26End Sub
27 28End Class The service is self-hosted The hosting code rs as follows 29Dim host As
ServiceHost = New ServiceHost(GetType(TearrwiessageSeMce))? 3ODim binding As Basic
HttpBindngt New BasicHttpBindiig(BasicHttpSecurityMode. None) 31
host.AddServiceEndpoint( “MyAppication lTearrtAessageService”, binding Thttp /Ilac aihost.
1 2345) 32host Open() You need to ensure that all clients calling GetMessage will retrieve
the same string, even if the message is upd(ed by clients calling PutMessage what should
you do?
A.
Redefine the message string in line 14, as follows. Shared message As String “Today’s
Message” Then change the implementation of PutMessage in lines 22-26 to the following
Public Sub PutMessage(ByVal message As rng) – Implements
ITean-MessageService.PutMessage TeamMessageSenAce.message = message End Sub
B.
Add the following attribute to the TeamMessageService class, before line 10.
<ServceBehavior(lnstanceContextMode lnstanceContextMode. Single)>
C.
Add the following attribute to the TeamMessageService class, before line 1 0002E
<ServiceBehavior( lnstanceContextll ode. = InstanceContextMode. PerSession)>
D.
Pass a service instance to the instancing code in line 29, as follows. Dim host As
ServiceHost z New ServiceHost(New TeamMessageServiceO)