static void Main(string[] args)
        {
            try
            {
                ParseArgs(args);

                // Send messages to queue which does not require session
                Console.Title = "Order Client";

                // Create sender to Order Service
                ChannelFactory <IOrderServiceContract> sendChannelFactory = new ChannelFactory <IOrderServiceContract>(SampleManager.OrderSendClientConfigName);
                IOrderServiceContract clientChannel = sendChannelFactory.CreateChannel();
                ((IChannel)clientChannel).Open();

                // Send messages
                orderQuantity = new Random().Next(10, 30);
                Console.WriteLine("Sending {0} messages to {1}...", orderQuantity, SampleManager.OrderQueueName);
                PlaceOrder(clientChannel);

                // Close sender
                ((IChannel)clientChannel).Close();
                sendChannelFactory.Close();
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception occurred: {0}", exception);
                SampleManager.ExceptionOccurred = true;
            }

            Console.WriteLine("\nSender complete.");
            Console.WriteLine("\nPress [Enter] to exit.");
            Console.ReadLine();
        }
        static void PlaceOrder(IOrderServiceContract clientChannel)
        {
            // Send messages to queue which requires session:
            for (int i = 0; i < orderQuantity; i++)
            {
                using (OperationContextScope scope = new OperationContextScope((IContextChannel)clientChannel))
                {
                    OrderItem orderItem = RandomizeOrder();

                    // Assigning the session name
                    BrokeredMessageProperty property = new BrokeredMessageProperty();

                    // Correlating ServiceBus SessionId to CustomerId
                    property.SessionId = customerId;

                    // Add BrokeredMessageProperty to the OutgoingMessageProperties bag to pass on the session information
                    OperationContext.Current.OutgoingMessageProperties.Add(BrokeredMessageProperty.Name, property);
                    clientChannel.Order(orderItem);
                    SampleManager.OutputMessageInfo("Order", string.Format("{0} [{1}]", orderItem.ProductId, orderItem.Quantity), customerId);
                    Thread.Sleep(200);
                }
            }
        }
Esempio n. 3
0
 public TransportService(IOrderServiceContract orderServiceContract)
 {
     serviceHost = new ServiceHost(orderServiceContract);
 }