public static void OutputMessageInfo(string action, PingData pingData) { lock (typeof(SampleManager)) { Console.ForegroundColor = colors[int.Parse(pingData.SenderId)]; Console.WriteLine("{0}: Message [{1}].", action, pingData.Message); Console.ResetColor(); } }
static void SendMessages(IPingServiceContract clientChannel) { // Send messages to queue which requires session: for (int i = 0; i < numberOfMessages; i++) { // Send message PingData message = CreatePingData(); clientChannel.Ping(message); SampleManager.OutputMessageInfo("Send", message); Thread.Sleep(200); } }
public void Ping(PingData pingData) { // Get the message properties var incomingProperties = OperationContext.Current.IncomingMessageProperties; BrokeredMessageProperty property = (BrokeredMessageProperty)incomingProperties[BrokeredMessageProperty.Name]; // Print message SampleManager.OutputMessageInfo("Receive", pingData); //Complete the Message ReceiveContext receiveContext; if (ReceiveContext.TryGet(incomingProperties, out receiveContext)) { receiveContext.Complete(TimeSpan.FromSeconds(10.0d)); } else { throw new InvalidOperationException("Receiver is in peek lock mode but receive context is not available!"); } }