示例#1
0
        private static void MessageOnly()
        {
            var transportClientEndpointBehavior = new TransportClientEndpointBehavior
            {
                TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sendKeyName, sendKeyValue)
            };

            var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, _queueName);

            var netMessagingBinding = new NetMessagingBinding
            {
                PrefetchCount = 10,
                TransportSettings = new NetMessagingTransportSettings
                {
                    BatchFlushInterval = TimeSpan.FromSeconds(0)
                }
            };

            var serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IRequest)),
                                                        netMessagingBinding,
                                                        new EndpointAddress(serviceUri));
            serviceEndpoint.Behaviors.Add(transportClientEndpointBehavior);
            var channelFactory = new ChannelFactory<IRequest>(serviceEndpoint);
            var channel = channelFactory.CreateChannel();
            Console.WriteLine("Press any key to send message...");
            Console.ReadKey();
            channel.SendMessage("Hello from wcf client");
            Console.WriteLine("Message sent");
            Console.ReadKey();
        }
示例#2
0
        private static void MessageWithContext()
        {
            var transportClientEndpointBehavior = new TransportClientEndpointBehavior
            {
                TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sendKeyName, sendKeyValue)
            };

            var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, _queueName);

            var netMessagingBinding = new NetMessagingBinding
            {
                PrefetchCount = 10,
                TransportSettings = new NetMessagingTransportSettings
                {
                    // this is polling interval
                    BatchFlushInterval = TimeSpan.FromSeconds(0)
                }
            };

            var serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IRequest)),
                                                        netMessagingBinding,
                                                        new EndpointAddress(serviceUri));
            serviceEndpoint.Behaviors.Add(transportClientEndpointBehavior);
            var channelFactory = new ChannelFactory<IRequest>(serviceEndpoint);
            var channel = channelFactory.CreateChannel();
            Console.WriteLine("Press any key to send message...");
            Console.ReadKey();

            using (new OperationContextScope((IContextChannel)channel))
            {
                var brokeredMessageProperty = new BrokeredMessageProperty
                {
                    Label = "MyLabel",
                    MessageId = Guid.NewGuid().ToString()
                };
                brokeredMessageProperty.Properties.Add("Author", "Paolo Salvatori");
                brokeredMessageProperty.Properties.Add("Email", "[email protected]");
                brokeredMessageProperty.Properties.Add("Country", "Italy");
                brokeredMessageProperty.Properties.Add("Priority", 1);
                OperationContext.Current.OutgoingMessageProperties.Add(BrokeredMessageProperty.Name, brokeredMessageProperty);
                channel.SendMessageWithContext("Hello from wcf client with context");

            }

            Console.WriteLine("Message sent");
            Console.ReadKey();
        }
示例#3
0
        static void Main(string[] args)
        {
            var transportClientEndpointBehavior = new TransportClientEndpointBehavior
            {
                TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(listenKeyName, listenKeyValue)
            };

            var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, _queueName);

            // Instantiate the host with the contract and URI.
            var host = new ServiceHost(typeof(RequestService), serviceUri);

            var netMessagingBinding = new NetMessagingBinding
            {
                PrefetchCount = 10,
                TransportSettings = new NetMessagingTransportSettings
                {
                    // this is polling interval
                    BatchFlushInterval = TimeSpan.FromSeconds(0)
                }
            };

            // Add the service endpoints to the service host
            host.AddServiceEndpoint(typeof(IRequest), netMessagingBinding, string.Empty);

            Console.WriteLine("Listening... ");
            Console.Write(" - ");
            Console.WriteLine(host.Description.Endpoints[0].Address.Uri.AbsoluteUri);

            foreach (var endpoint in host.Description.Endpoints)
            {
                endpoint.Behaviors.Add(transportClientEndpointBehavior);
            }

            host.Open();

            Console.ReadLine();
        }
示例#4
0
		static void SimpleWcfClientServiceViaServiceBus()
		{
			NetMessagingBinding binding = new NetMessagingBinding();

			// Start up the Echo WCF service listening via Azure Service Bus
			ServiceHost host = new ServiceHost(typeof(EchoService));
			ServiceEndpoint echoServiceEndpoint
				= host.AddServiceEndpoint(typeof(IEchoService), binding, QueueAddress);
			echoServiceEndpoint.Behaviors.Add(new TransportClientEndpointBehavior(TokenProvider));
			host.Open();
			Console.WriteLine("WCF service up and running, listening on {0}", QueueAddress);

			// Create a WCF channel factory and client to send message to the Azure Service Bus
			ChannelFactory<IEchoService> factory = new ChannelFactory<IEchoService>
				(binding, new EndpointAddress(QueueAddress));
			factory.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior(TokenProvider));
			IEchoService proxy = factory.CreateChannel();

			// Send messages to the service
			string requestMessage = "Hello World";
			proxy.Echo(requestMessage);
			Console.WriteLine("Message sent to the queue - '{0}' ", requestMessage);

			// clean up the client and service
			factory.Close();
			host.Close();
		}