Esempio n. 1
0
        static void Main(string[] args)
        {
            string serviceAddress = "soap.udp://224.0.0.1:40000";
            UdpBinding myBinding = new UdpBinding();
            ServiceHost host = new ServiceHost(typeof(StockTickerService), new Uri(serviceAddress));
            host.AddServiceEndpoint(typeof(IStockTicker), myBinding, "");
            //ServiceMetadataBehavior smb = (ServiceMetadataBehavior)host.Description.Behaviors.Find<ServiceMetadataBehavior>();
            ////if (smb == null)
            ////{
            ////    smb = new ServiceMetadataBehavior();
            ////    //smb.HttpGetEnabled = true;
            ////    host.Description.Behaviors.Add(smb);
            ////}
            //  if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
            //      {
            //           ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
            //           behavior.HttpGetEnabled = true;
            //           behavior.HttpGetUrl = new Uri("http://224.0.0.1:40000");
            //           host.Description.Behaviors.Add(behavior);
            //      }

            host.Open();
            Console.WriteLine("Start receiving stock information");
            Console.WriteLine("{0} is up and running with following endpoint(s)-", host.Description.ServiceType);
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string serviceAddress = "soap.udp://224.0.0.1:40000";
            UdpBinding myBinding = new UdpBinding();
            ServiceHost host = new ServiceHost(typeof(StockTickerService), new Uri(serviceAddress));
            host.AddServiceEndpoint(typeof(IStockTicker), myBinding, "");

            host.Open();
            Console.WriteLine("Start receiving stock information");
            Console.WriteLine("{0} is up and running with following endpoint(s)-", host.Description.ServiceType);
            Console.ReadLine();
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     string baseAddress = "soap.udp://224.0.0.1:40000";
     UdpBinding myBinding = new UdpBinding();
     ChannelFactory<IStockTicker> factory = new ChannelFactory<IStockTicker>(myBinding, new EndpointAddress(baseAddress));
     IStockTicker proxy = factory.CreateChannel();
     while (true)
     {
         // This will continue to mulicast stock information
         proxy.SendStockInfo(GetStockInfo());
         int x = proxy.ResponseStockInfo(GetStockInfo());
         Console.WriteLine(String.Format("sent stock info at {0}, the cound is {1}", DateTime.Now,x));
         // Wait for one second before sending another update
         System.Threading.Thread.Sleep(new TimeSpan(0, 0, 1));
     }
 }
        internal static bool TryCreate(BindingElementCollection bindingElements, out Binding binding)
        {
            binding = null;

            if (bindingElements.Count > 2)
            {
                return(false);
            }

            UdpTransportBindingElement        transport = null;
            TextMessageEncodingBindingElement encoding  = null;

            foreach (BindingElement bindingElement in bindingElements)
            {
                if (bindingElement is UdpTransportBindingElement)
                {
                    transport = bindingElement as UdpTransportBindingElement;
                }
                else if (bindingElement is TextMessageEncodingBindingElement)
                {
                    encoding = bindingElement as TextMessageEncodingBindingElement;
                }
                else
                {
                    return(false);
                }
            }

            if (transport == null || encoding == null)
            {
                return(false);
            }

            UdpBinding udpBinding = new UdpBinding(transport, encoding);

            if (!udpBinding.BindingElementsPropertiesMatch(transport, encoding))
            {
                return(false);
            }

            binding = udpBinding;
            return(true);
        }
Esempio n. 5
0
        internal static bool TryCreate(BindingElementCollection bindingElements, out Binding binding)
        {
            binding = null;

            if (bindingElements.Count > 2)
            {
                return false;
            }

            UdpTransportBindingElement transport = null;
            TextMessageEncodingBindingElement encoding = null;
            
            foreach (BindingElement bindingElement in bindingElements)
            {
                if (bindingElement is UdpTransportBindingElement)
                {
                    transport = bindingElement as UdpTransportBindingElement;
                }
                else if (bindingElement is TextMessageEncodingBindingElement)
                {
                    encoding = bindingElement as TextMessageEncodingBindingElement;
                }
                else
                {
                    return false;
                }
            }

            if (transport == null || encoding == null)
            {
                return false;
            }

            UdpBinding udpBinding = new UdpBinding(transport, encoding);

            if (!udpBinding.BindingElementsPropertiesMatch(transport, encoding))
            {
                return false;    
            }

            binding = udpBinding;
            return true;
        }
Esempio n. 6
0
        private void sendPublicMessage(object sender, DoWorkEventArgs e)
        {
            try
            {
                string message = (string)e.Argument;
                foreach(Peer p in Mesh.Values) {
                    if (p.UdpAddress != null)
                    {
                        if (p.MAC_Hash.Equals(Self.MAC_Hash))
                        {
                            continue;
                        }

                        Binding b = new UdpBinding();

                        var factory = new ChannelFactory<IChatService>(b, p.UdpAddress.ToString());
                        var channel = factory.CreateChannel();

                        channel.Chat(message, Self.MAC_Hash);
                    }
                }
            }
            catch (Exception ex)
            {

                Debug.WriteLine(ex);
            }
        }
Esempio n. 7
0
        private void registrationClient(Uri uri)
        {
            Debug.WriteLine("Registration: " + uri);
            try
            {
                if (uri != null)
                {
                    Binding b = new UdpBinding();

                    var factory = new ChannelFactory<IChatService>(b, uri.ToString());
                    var channel = factory.CreateChannel();

                    channel.Hello(Self.Address, Self.Chatter.Nick, Self.MAC_Hash);
                }

            }
            catch (Exception ex)
            {

                Debug.WriteLine(ex);
            }
        }