News:

SQL Table To C# Entity Model ConverterEntity Model (Class Properties) to SQL Table ConverterIf you encounter any trouble visiting our site, please contact us.

Advertisement

Looking for job. Try JobLoader- First ever job search engine in Bangladesh. All open bd jobs now a single mouse click away.

;
01 [ServiceContract]
02 public interface ITeamMessageService
03 {
04 [OperationContract]
05 string GetMessage();
07 [OperationContract]
08 void PutMessage(string message);
09 }

The code for the service class is as follows

10 public class TeamMessageService: ITeamMessageService
11 {
12 Guid key = Guid.NewGuid();
13 string message = "Today's Message":
14 public string GetMessage()
15 {
16 return stringFormat("Message:{0} Key:{1}",
17 message, key);
18 }
19 public void PutMessage(string message)
20 {
21 this.message = message;
22 }
23 }

The service is self-hosted. The hosting code is as follows.

24 ServiceHost host = New ServiceHost(GetType(TeamMessageService));
25 BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None):
26 host.AddServiceEndpoint(MyApplication.ITeamMessageService, binding, "http://
localhost:12345");
27 host Open();

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?

  1. Add the following attribute to the TeamMessageService class, before line 10.

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

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]

    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;
  3. Pass a service instance to the instancing code in line 24, as follows.

    ServiceHost host = new ServiceHost(new TeamMessageService());
  4. 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.PutMessage }
Answer: Answer is a
comments powered by Disqus
Advertisement

BCS Preparation now even more easy. ReadBD is the place where you can find all kind of resources to be successful in BCS,Bank,Islami Bank exam and interview.

Looking for job. Try JobLoader- First ever job search engine in Bangladesh. All open bd jobs now a single mouse click away.

;