using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace CorsService { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MessageService" in code, svc and config file together. // NOTE: In order to launch WCF Test Client for testing this service, please select MessageService.svc or MessageService.svc.cs at the Solution Explorer and start debugging. public class MessageService : IMessageService { private static List _messages = new List(); public void SendMessage(string sender, string recipient, string message) { EmailMessage msg = new EmailMessage(sender, recipient, message); _messages.Add(msg); } public string ReadLastMessage() { if (_messages.Count == 0) return ""; return _messages[_messages.Count - 1].MessageText; } public string ReadMessage(int msgId) { try { EmailMessage msg = _messages[msgId]; return msg.MessageText; } catch // (ArgumentOutOfRangeException e) { return "Bad Id"; } } public EmailMessage ModifyMessage(int msgId, EmailMessage messageChanges) { try { EmailMessage msg = _messages[msgId]; msg.Sender = messageChanges.Sender; msg.Recipient = messageChanges.Recipient; msg.MessageText = messageChanges.MessageText; return msg; } catch // (ArgumentOutOfRangeException e) { return new EmailMessage("Broken", "Broken", "Broken"); } } public EmailMessage[] ReadAllMessages(string recipient, string keyWord) { return _messages.ToArray(); } public void DeleteMessage(int msgId) { try { _messages.RemoveAt(msgId); } catch // (ArgumentOutOfRangeException e) { } } } }