Esempio n. 1
0
    public static void Main()
    {
        var binding = new NetPeerTcpBinding();

        binding.Resolver.Mode           = PeerResolverMode.Custom;
        binding.Resolver.Custom.Address = new EndpointAddress("net.tcp://localhost:8086");
        var tcp = new NetTcpBinding()
        {
            TransactionFlow = false
        };

        tcp.Security.Mode = SecurityMode.None;
        binding.Resolver.Custom.Binding = tcp;

        binding.Security.Mode = SecurityMode.None;
        IFooChannel proxy = new DuplexChannelFactory <IFooChannel> (
            new Foo(),
            binding,
            new EndpointAddress("net.p2p://samplemesh/SampleService")
            ).CreateChannel();

        proxy.Open();
        proxy.SendMessage("TEST FOR ECHO");
        Console.WriteLine(proxy.SessionId);
        Console.WriteLine("type [CR] to quit");
        Console.ReadLine();
    }
Esempio n. 2
0
        private bool Connect()
        {
            try
            {
                if (null != m_clientChannel)
                {
                    ((ICommunicationObject)m_clientChannel).Close();
                }
                if (null == m_factory)
                {
                    EndpointAddress   address = new EndpointAddress("net.p2p://ceebeetleclient");
                    NetPeerTcpBinding binding = new NetPeerTcpBinding();

                    binding.Security.Mode = SecurityMode.None;
                    m_site    = new InstanceContext(m_peer);
                    m_factory = new DuplexChannelFactory <ICeebeetlePeer>(m_site, binding, address);
                }
                m_clientChannel = m_factory.CreateChannel();
                ((ICommunicationObject)m_clientChannel).Open();
                m_peer.OnConnected();
                return(true);
            }
            catch (CommunicationException commEx)
            {
                Error(string.Format("Communication exception connecting: {0}", commEx.Message));
            }
            catch (Exception ex)
            {
                Error(string.Format("Exception connecting: {0}", ex.Message));
            }
            return(false);
        }
Esempio n. 3
0
    public static void Main()
    {
        SetupPeerResolverService();

        ServiceHost       host    = new ServiceHost(typeof(Foo));
        NetPeerTcpBinding binding = new NetPeerTcpBinding();

        binding.Resolver.Mode           = PeerResolverMode.Custom;
        binding.Resolver.Custom.Address = new EndpointAddress("net.tcp://localhost:8086");
        var tcp = new NetTcpBinding()
        {
            TransactionFlow = false
        };

        tcp.Security.Mode = SecurityMode.None;
        binding.Resolver.Custom.Binding = tcp;

        binding.Security.Mode  = SecurityMode.None;
        binding.ReceiveTimeout = TimeSpan.FromSeconds(5);
        binding.OpenTimeout    = TimeSpan.FromSeconds(20);
        host.AddServiceEndpoint("IFoo",
                                binding, new Uri("net.p2p://samplemesh/SampleService"));
        host.Description.Behaviors.Find <ServiceBehaviorAttribute> ()
        .IncludeExceptionDetailInFaults = true;
        host.Open();
        Console.WriteLine("Hit [CR] key to close ...");
        Console.ReadLine();
        host.Close();

        peer_resolver.Close();
    }
        private ChannelFactory <IBroadcastReceiver <T> > GetChannelFactory()
        {
            ChannelFactory <IBroadcastReceiver <T> > channelFactory = null;

            if (Channel?.Mode == ChannelMode.Local)
            {
                var localBinding = new NetNamedPipeBinding();
                localBinding.Security.Mode = NetNamedPipeSecurityMode.Transport;

                var localEndpointUri = new Uri($"net.pipe://localhost/{Channel.Name}");
                var localEndpoint    = new EndpointAddress(localEndpointUri);

                channelFactory = new ChannelFactory <IBroadcastReceiver <T> >(localBinding);
                client         = channelFactory.CreateChannel(localEndpoint);
            }

            if (Channel?.Mode == ChannelMode.Mesh)
            {
                var meshBinding = new NetPeerTcpBinding();
                meshBinding.Security.Mode = SecurityMode.None;

                var meshEndpointUri = new Uri($"net.p2p://{Channel.Name}");
                var meshEndpoint    = new EndpointAddress(meshEndpointUri);

                channelFactory = new ChannelFactory <IBroadcastReceiver <T> >(meshBinding);
                client         = channelFactory.CreateChannel(meshEndpoint);
            }

            return(channelFactory);
        }
Esempio n. 5
0
        public void StartService()
        {
            var binding = new NetPeerTcpBinding();

            binding.Security.Mode = SecurityMode.None;

            var endpoint = new ServiceEndpoint(
                ContractDescription.GetContract(typeof(IPing1)),
                binding,
                new EndpointAddress("net.p2p://SimpleP2P"));

            Host        = new PingImplementation();
            Host.MyHost = User;


            _factory = new System.ServiceModel.DuplexChannelFactory <IPing1>(new InstanceContext(Host), endpoint);

            var channel = _factory.CreateChannel();

            ((ICommunicationObject)channel).Open();

            // wait until after the channel is open to allow access.
            Channel        = channel;
            Host.myChannel = Channel;
        }
Esempio n. 6
0
        public static TChannel OpenPeerChannel <TService, TChannel>() where TChannel : IClientChannel
        {
            var portnumber            = DeNSo.Configuration.Extensions.P2P().NetworkPort;
            NetPeerTcpBinding binding = new NetPeerTcpBinding()
            {
                Port = portnumber,
                Name = GetURI().OriginalString + "@" + portnumber,
            };

            binding.Security.Mode = SecurityMode.None;

            EndpointAddress           address       = new EndpointAddress(GetURI().OriginalString);
            ChannelFactory <TChannel> sourceFactory = new ChannelFactory <TChannel>(binding, address);
            //sourceFactory.Credentials.Peer.MeshPassword = DeNSo.Configuration.Extensions.P2P().NetworkPassword;

            TChannel sourceProxy = (TChannel)sourceFactory.CreateChannel();

            MessagePropagationFilter remoteOnlyFilter = new MessagePropagationFilter();

            PeerNode peerNode = ((IClientChannel)sourceProxy).GetProperty <PeerNode>();

            //peerNode.MessagePropagationFilter = remoteOnlyFilter;

            sourceProxy.Open();
            return(sourceProxy);
        }
        public bool StartPeerService()
        {
        #pragma warning disable 618
            var binding = new NetPeerTcpBinding
            {
                Security = { Mode = SecurityMode.None }
            };
        #pragma warning restore 618
            var endpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IPingService)), binding, new EndpointAddress("net.p2p://YoutubeFileShare"));
            Peer.Host     = PingService;
            _factory      = new DuplexChannelFactory <IPingService>(new InstanceContext(Peer.Host), endpoint);
            Peer.Channel  = _factory.CreateChannel();
            Communication = (ICommunicationObject)Peer.Channel;

            if (Communication != null)
            {
                Communication.Opened += CommunicationOnOpened;
                try
                {
                    Communication.Open();
                    if (_isServiceStarted)
                    {
                        return(_isServiceStarted);
                    }
                }
                catch (PeerToPeerException e)
                {
                    throw new PeerToPeerException($"error establishing peer services");
                }
            }

            return(_isServiceStarted);
        }
Esempio n. 8
0
        public static void Main()
        {
            InstanceContext   ic   = new InstanceContext(new ChatClient("Marcos"));
            NetPeerTcpBinding nptb = new NetPeerTcpBinding();
//			NetTcpBinding ntb = new NetTcpBinding ();
//			CustomBinding ntb = new CustomBinding ();
//			ntb.Elements.Add (new TextMessageEncodingBindingElement ());
//			ntb.Elements.Add (new TcpTransportBindingElement ());
            BasicHttpBinding ntb = new BasicHttpBinding();

//			ntb.Security.Mode = SecurityMode.None;
            nptb.Resolver.Custom.Address = new EndpointAddress("http://localhost:8080/ChatServer");
            nptb.Resolver.Custom.Binding = ntb;
            nptb.Resolver.Mode           = PeerResolverMode.Auto;
//			nptb.Resolver.ReferralPolicy = PeerReferralPolicy.Service;
            nptb.Security.Mode = SecurityMode.None;
//			DuplexChannelFactory<IChatService> factory =
//				new DuplexChannelFactory<IChatService> (ic,
//				                                        nptb,
//				                                        new EndpointAddress ("net.p2p://chatMesh/ChatServer"));
            IChatService channel =
                DuplexChannelFactory <IChatService> .CreateChannel(ic,
                                                                   nptb,
                                                                   new EndpointAddress ("net.p2p://chatMesh/ChatServer"));

//			channel.Open ();
//			Console.WriteLine ("Here!");
            channel.Join("Marcos");
            // Right here, run the same process separately.
            Console.ReadLine();
            channel.Leave("Marcos");
            ((IChannel)channel).Close();
//			factory.Close ();
        }
        public void DefaultValuesForCustom()
        {
            var n = new NetPeerTcpBinding();

            n.Resolver.Mode            = PeerResolverMode.Custom;
            n.Resolver.Custom.Resolver = new DummyResolver();

            Assert.AreEqual(EnvelopeVersion.Soap12, n.EnvelopeVersion, "#1");
            Assert.IsNull(n.ListenIPAddress, "#2");
            Assert.AreEqual(0x10000, n.MaxReceivedMessageSize, "#3");
            Assert.AreEqual(0, n.Port, "#4");
            Assert.IsNotNull(n.ReaderQuotas, "#5");

            Assert.IsFalse(((IBindingRuntimePreferences)n).ReceiveSynchronously, "#6");

            var bec = n.CreateBindingElements();

            Assert.IsNotNull(bec.Find <PeerCustomResolverBindingElement> (), "#bec0");
            Assert.IsNotNull(bec.Find <BinaryMessageEncodingBindingElement> (), "#bec1");
            Assert.AreEqual(3, bec.Count, "#bec2");

            var tr = bec.Find <PeerTransportBindingElement> ();

            Assert.IsNotNull(tr, "#tr1");
        }
Esempio n. 10
0
        private void ConnectToMesh()
        {
            try
            {
                _instanceContext = new InstanceContext(this);

                _binding = new NetPeerTcpBinding("SharedTextEditorBinding");

                _channelFactory = new DuplexChannelFactory <ISharedTextEditorP2PChannel>(_instanceContext,
                                                                                         "SharedTextEditorEndpointP2P");

                var endpointAddress = new EndpointAddress(_channelFactory.Endpoint.Address.ToString());

                _channelFactory.Endpoint.Address = endpointAddress;
                _p2pChannel = _channelFactory.CreateChannel();

                //setup the event handlers for handling online/offline events
                _statusHandler = _p2pChannel.GetProperty <IOnlineStatus>();

                if (_statusHandler != null)
                {
                    _statusHandler.Online  += ostat_Online;
                    _statusHandler.Offline += ostat_Offline;
                }

                //call empty method to force connection to mesh
                _p2pChannel.InitializeMesh();
                _editor.UpdateConnectionState(true);
            }
            catch (Exception)
            {
                _editor.UpdateConnectionState(false);
            }
        }
        public void Open(IChannel channel)
        {
            Channel = channel;
            host    = new ServiceHost(this);

            if (channel?.Mode == ChannelMode.Local)
            {
                var localBinding = new NetNamedPipeBinding();
                localBinding.Security.Mode = NetNamedPipeSecurityMode.Transport;

                var localEndpoint = new Uri($"net.pipe://localhost/{channel.Name}");
                host.AddServiceEndpoint(typeof(IBroadcastReceiver <T>), localBinding, localEndpoint);
            }

            if (channel?.Mode == ChannelMode.Mesh)
            {
                var meshBinding = new NetPeerTcpBinding();
                meshBinding.Resolver.Mode = PeerResolverMode.Pnrp;
                meshBinding.Security.Mode = SecurityMode.None;

                var meshEndpoint = new Uri($"net.p2p://{channel.Name}");
                host.AddServiceEndpoint(typeof(IBroadcastReceiver <T>), meshBinding, meshEndpoint);
            }

            host.Open();
        }
Esempio n. 12
0
        // Host the receiver within this EXE console application.
        public static void Main()
        {
            string recognizedPublisherName = ConfigurationManager.AppSettings["publisherQName"];

            ServiceHost receiver = new ServiceHost(new BroadcastReceiver());

            //this settings specifies that only messages signed with above cert should be accepted.
            NetPeerTcpBinding binding = new NetPeerTcpBinding("Binding1");

            // set peer credentials
            X509Certificate2 certificate = GetCertificate(StoreName.TrustedPeople, StoreLocation.CurrentUser, recognizedPublisherName, X509FindType.FindBySubjectDistinguishedName);

            receiver.Credentials.Peer.MessageSenderAuthentication.CertificateValidationMode  = X509CertificateValidationMode.Custom;
            receiver.Credentials.Peer.MessageSenderAuthentication.CustomCertificateValidator = new PublisherValidator(certificate);

            // Open the ServiceHostBase to create listeners and start listening for messages.
            receiver.Open();

            // Retrieve the PeerNode associated with the receiver and register for online/offline events
            // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes.

            // use the first base address.
            string baseAddress = receiver.BaseAddresses[0].ToString();

            EndpointAddress lookFor = new EndpointAddress(baseAddress + "announcements");

            for (int i = 0; i < receiver.ChannelDispatchers.Count; ++i)
            {
                ChannelDispatcher channelDispatcher = receiver.ChannelDispatchers[i] as ChannelDispatcher;
                if (channelDispatcher != null)
                {
                    for (int j = 0; j < channelDispatcher.Endpoints.Count; ++j)
                    {
                        EndpointDispatcher endpointDispatcher = channelDispatcher.Endpoints[j];
                        if (endpointDispatcher.EndpointAddress == lookFor)
                        {
                            IOnlineStatus ostat = (IOnlineStatus)channelDispatcher.Listener.GetProperty <IOnlineStatus>();
                            if (ostat != null)
                            {
                                ostat.Online  += OnOnline;
                                ostat.Offline += OnOffline;
                                if (ostat.IsOnline)
                                {
                                    Console.WriteLine("**  Online");
                                }
                            }
                        }
                    }
                }
            }

            // The receiver can now receive broadcast announcements
            Console.WriteLine("**  The receiver is ready");
            Console.WriteLine("Press <ENTER> to terminate receiver.");
            Console.ReadLine();

            // Close the ServiceHostBase to shutdown the receiver
            receiver.Close();
        }
Esempio n. 13
0
        public static Binding CreateBinding(BindingType bindingType, long maxReceivedMessageSize)
        {
            Binding binding = null;

            if (bindingType == BindingType.Unknow)
            {
                return(binding);
            }

            switch (bindingType)
            {
            case BindingType.BasicHttpBinding:
                BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
                basicHttpBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                binding = basicHttpBinding;
                break;

            case BindingType.NetNamedPipeBinding:
                NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding();
                netNamedPipeBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                binding = netNamedPipeBinding;
                break;

            case BindingType.NetPeerTcpBinding:
                NetPeerTcpBinding netPeerTcpBinding = new NetPeerTcpBinding();
                netPeerTcpBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                binding = netPeerTcpBinding;
                break;

            case BindingType.NetTcpBinding:
                NetTcpBinding netTcpBinding = new NetTcpBinding();
                netTcpBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                binding = netTcpBinding;
                break;

            case BindingType.WSDualHttpBinding:
                WSDualHttpBinding wsDualHttpBinding = new WSDualHttpBinding();
                wsDualHttpBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                binding = wsDualHttpBinding;
                break;

            case BindingType.WSFederationHttpBinding:
                WSFederationHttpBinding wsFederationHttpBinding = new WSFederationHttpBinding();
                wsFederationHttpBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                binding = wsFederationHttpBinding;
                break;

            case BindingType.WSHttpBinding:
                WSHttpBinding wsHttpBinding = new WSHttpBinding();
                wsHttpBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                binding = wsHttpBinding;
                break;

            default:
                break;
            }

            return(binding);
        }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
        {
            if (endpointContext == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext");
            }

#pragma warning suppress 56506 // [....], endpointContext.Endpoint is never null
            if (endpointContext.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext.Binding");
            }

            if (endpointContext.Endpoint.Binding is CustomBinding)
            {
                BindingElementCollection elements = ((CustomBinding)endpointContext.Endpoint.Binding).Elements;

                Binding binding;
                TransportBindingElement transport = elements.Find <TransportBindingElement>();

                if (transport is HttpTransportBindingElement)
                {
                    if (WSHttpBindingBase.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (WSDualHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (BasicHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (NetHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                }
                else if (transport is MsmqTransportBindingElement && NetMsmqBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
                else if (transport is NamedPipeTransportBindingElement && NetNamedPipeBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
#pragma warning disable 0618
                else if (transport is PeerTransportBindingElement && NetPeerTcpBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
#pragma warning restore 0618
                else if (transport is TcpTransportBindingElement && NetTcpBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 创建传输协议
        /// </summary>
        /// <param name="binding">传输协议名称</param>
        /// <returns></returns>
        private static Binding CreateBinding(string binding)
        {
            Binding bindinginstance = null;

            if (binding.ToLower() == "basichttpbinding")
            {
                BasicHttpBinding ws = new BasicHttpBinding();
                ws.MaxReceivedMessageSize = 65535000;
                bindinginstance           = ws;
            }
            else if (binding.ToLower() == "netnamedpipebinding")
            {
                NetNamedPipeBinding ws = new NetNamedPipeBinding();
                ws.MaxReceivedMessageSize = 65535000;
                bindinginstance           = ws;
            }
            else if (binding.ToLower() == "netpeertcpbinding")
            {
                NetPeerTcpBinding ws = new NetPeerTcpBinding();
                ws.MaxReceivedMessageSize = 65535000;
                bindinginstance           = ws;
            }
            else if (binding.ToLower() == "nettcpbinding")
            {
                NetTcpBinding ws = new NetTcpBinding();
                ws.MaxReceivedMessageSize = 65535000;
                ws.Security.Mode          = SecurityMode.None;
                bindinginstance           = ws;
            }
            else if (binding.ToLower() == "wsdualhttpbinding")
            {
                WSDualHttpBinding ws = new WSDualHttpBinding();
                ws.MaxReceivedMessageSize = 65535000;

                bindinginstance = ws;
            }
            else if (binding.ToLower() == "webhttpbinding")
            {
                WebHttpBinding ws = new WebHttpBinding();
                ws.MaxReceivedMessageSize = 65535000;
                bindinginstance           = ws;
            }
            else if (binding.ToLower() == "wsfederationhttpbinding")
            {
                WSFederationHttpBinding ws = new WSFederationHttpBinding();
                ws.MaxReceivedMessageSize = 65535000;
                bindinginstance           = ws;
            }
            else if (binding.ToLower() == "wshttpbinding")
            {
                WSHttpBinding ws = new WSHttpBinding(SecurityMode.None);
                ws.MaxReceivedMessageSize = 65535000;
                ws.Security.Message.ClientCredentialType   = System.ServiceModel.MessageCredentialType.Windows;
                ws.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
                ws.ReaderQuotas.MaxStringContentLength     = 65535000;
                bindinginstance = ws;
            }
            return(bindinginstance);
        }
        public static Binding CreateBinding(string bindingName)
        {
            Binding result = null;

            try
            {
                if (string.Compare(bindingName, typeof(WSHttpBinding).FullName, true) == 0)
                {
                    result = new WSHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WS2007HttpBinding).FullName, true) == 0)
                {
                    result = new WS2007HttpBinding();
                }
                else if (string.Compare(bindingName, typeof(BasicHttpBinding).FullName, true) == 0)
                {
                    result = new BasicHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WSDualHttpBinding).FullName, true) == 0)
                {
                    result = new WSDualHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WS2007FederationHttpBinding).FullName, true) == 0)
                {
                    result = new WS2007FederationHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WSFederationHttpBinding).FullName, true) == 0)
                {
                    result = new WSFederationHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(NetNamedPipeBinding).FullName, true) == 0)
                {
                    result = new NetNamedPipeBinding();
                }
                else if (string.Compare(bindingName, typeof(NetMsmqBinding).FullName, true) == 0)
                {
                    result = new NetMsmqBinding();
                }
                else if (string.Compare(bindingName, typeof(MsmqIntegrationBinding).FullName, true) == 0)
                {
                    result = new MsmqIntegrationBinding();
                }
                else if (string.Compare(bindingName, typeof(NetTcpBinding).FullName, true) == 0)
                {
                    result = new NetTcpBinding();
                }
                else if (string.Compare(bindingName, typeof(NetPeerTcpBinding).FullName, true) == 0)
                {
                    result = new NetPeerTcpBinding();
                }
            }
            catch
            {
                result = new BasicHttpBinding(BasicHttpSecurityMode.None);
            }

            return(result);
        }
Esempio n. 17
0
        // Host the chat instance within this EXE console application.
        public static void Main(string[] args)
        {
            Console.WriteLine("Enter your nickname [default=DefaultName]: ");
            string member = Console.ReadLine();

            Console.WriteLine("Enter the mesh password: "******"")
            {
                member = "DefaultName";
            }

            // Construct InstanceContext to handle messages on callback interface.
            // An instance of ChatApp is created and passed to the InstanceContext.
            InstanceContext site = new InstanceContext(new ChatApp());

            // Create the participant with the given endpoint configuration
            // Each participant opens a duplex channel to the mesh
            // participant is an instance of the chat application that has opened a channel to the mesh
            NetPeerTcpBinding binding = new NetPeerTcpBinding("SecureChatBinding");

            ChannelFactory <IChatChannel> cf = new DuplexChannelFactory <IChatChannel>(site, "SecureChatEndpoint");

            //for PeerAuthenticationMode.Password, you need to specify a password
            cf.Credentials.Peer.MeshPassword = password;
            IChatChannel participant = cf.CreateChannel();

            // Retrieve the PeerNode associated with the participant and register for online/offline events
            // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes.
            IOnlineStatus ostat = participant.GetProperty <IOnlineStatus>();

            ostat.Online  += new EventHandler(OnOnline);
            ostat.Offline += new EventHandler(OnOffline);

            // Print instructions to user
            Console.WriteLine("{0} is ready", member);
            Console.WriteLine("Type chat messages after going Online");
            Console.WriteLine("Press q<ENTER> to terminate this instance.");

            // Announce self to other participants
            participant.Join(member);

            while (true)
            {
                string line = Console.ReadLine();
                if (line == "q")
                {
                    break;
                }
                participant.Chat(member, line);
            }
            // Leave the mesh and close the proxy
            participant.Leave(member);

            ((IChannel)participant).Close();
            cf.Close();
        }
Esempio n. 18
0
        /// <summary>
        /// Loads the binding's settings from a XML encoded string.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentException">Thrown if the settings are not valid.</exception>
        private void LoadSettings(NetPeerTcpBinding binding, string settings)
        {
            if (string.IsNullOrWhiteSpace(settings))
            {
                return;
            }

            throw new NotImplementedException();    // $todo(jeff.lill): Implement this
        }
Esempio n. 19
0
        internal static void ConfigureNone(Collection <ServiceEndpoint> endpoints)
        {
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                Binding binding = endpoint.Binding;

                if (binding is BasicHttpBinding)
                {
                    BasicHttpBinding basicBinding = (BasicHttpBinding)binding;
                    basicBinding.Security.Mode = BasicHttpSecurityMode.None;
                    continue;
                }
                if (binding is NetTcpBinding)
                {
                    NetTcpBinding tcpBinding = (NetTcpBinding)binding;
                    tcpBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is NetPeerTcpBinding)
                {
                    NetPeerTcpBinding peerBinding = (NetPeerTcpBinding)binding;
                    peerBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is NetNamedPipeBinding)
                {
                    NetNamedPipeBinding pipeBinding = (NetNamedPipeBinding)binding;
                    pipeBinding.Security.Mode = NetNamedPipeSecurityMode.None;
                    continue;
                }
                if (binding is WSHttpBinding)
                {
                    WSHttpBinding wsBinding = (WSHttpBinding)binding;
                    wsBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is WSDualHttpBinding)
                {
                    WSDualHttpBinding wsDualBinding = (WSDualHttpBinding)binding;
                    wsDualBinding.Security.Mode = WSDualHttpSecurityMode.None;
                    continue;
                }
                if (binding is NetMsmqBinding)
                {
                    NetMsmqBinding msmqBinding = (NetMsmqBinding)binding;
                    msmqBinding.Security.Mode = NetMsmqSecurityMode.None;
                    continue;
                }
                if (binding is CustomBinding && endpoint.Contract.ContractType == typeof(IMetadataExchange))
                {
                    Trace.WriteLine("No declarative security for MEX endpoint when adding it programmatically");
                    continue;
                }
                throw new InvalidOperationException(binding.GetType() + "is unsupprted with ServiceSecurity.None");
            }
        }
Esempio n. 20
0
        public static Binding WcfBindingFactory(string bindingtype, string bidingconfigname)
        {
            Binding binding = null;

            if (!string.IsNullOrEmpty(bindingtype) && !string.IsNullOrEmpty(bidingconfigname))
            {
                switch (bindingtype)
                {
                case "basicHttpBinding":
                    binding = new BasicHttpBinding(bidingconfigname);
                    break;

                case "basicHttpContextBinding":
                    binding = new BasicHttpContextBinding(bidingconfigname);
                    break;

                case "wsHttpBinding":
                    binding = new WSHttpBinding(bidingconfigname);
                    break;

                case "wsHttpContextBinding":
                    binding = new WSHttpContextBinding(bidingconfigname);
                    break;

                case "netTcpBinding":
                    binding = new NetTcpBinding(bidingconfigname);
                    break;

                case "netTcpContextBinding":
                    binding = new NetTcpContextBinding(bidingconfigname);
                    break;

                case "netPeerTcpBinding":
                    binding = new NetPeerTcpBinding(bidingconfigname);
                    break;

                case "netNamedPipeBinding":
                    binding = new NetNamedPipeBinding(bidingconfigname);
                    break;

                case "webHttpBinding":
                    binding = new WSHttpBinding(bidingconfigname);
                    break;

                case "wsDualHttpBinding":
                    binding = new WSDualHttpBinding(bidingconfigname);
                    break;

                case "customBinding":
                    binding = new CustomBinding(bidingconfigname);
                    break;
                }
            }

            return(binding);
        }
        public bool IniciarCanalP2P(String nombreNodo, String nombreRed, String password)
        {
            CheckDispose();

            mNombreNodo = nombreNodo;
            mNombreRed  = nombreRed;
            mPassword   = password;

            if (string.IsNullOrEmpty(password.Trim()))
            {
                mPassword = "******";
            }
            else
            {
                mPassword = password.Trim();
            }

            mContextoDeInstancia = new InstanceContext(this);

            NetPeerTcpBinding p2pBinding = new NetPeerTcpBinding();

            p2pBinding.Name = "BindingDefault";
            p2pBinding.Port = 0;                          //puerto dinámico
            p2pBinding.MaxReceivedMessageSize = 70000000; //(70mb)
            p2pBinding.Resolver.Mode          = PeerResolverMode.Pnrp;

            String          bindingInfo     = "net.p2p://";
            EndpointAddress epa             = new EndpointAddress(String.Concat(bindingInfo, mNombreRed));
            ServiceEndpoint serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IContratoDeServicio)), p2pBinding, epa);

            mFabricaDeCanalesDuplex = new DuplexChannelFactory <IContratoDeServicioCliente>(mContextoDeInstancia, serviceEndpoint);
            mFabricaDeCanalesDuplex.Credentials.Peer.MeshPassword = mPassword;
            mParticipanteP2P = mFabricaDeCanalesDuplex.CreateChannel();

            mAyudanteImagen   = new AyudanteImagen(mParticipanteP2P.ServicioGestionarImagen, mNombreNodo);
            mAyudanteChat     = new AyudanteChat(mParticipanteP2P.ServicioGestionarChat);
            mAyudanteFichero  = new AyudanteFichero(mParticipanteP2P.ServicioGestionarFichero);
            mAyudanteAudio    = new AyudanteStream(mParticipanteP2P, mNombreNodo, mParticipanteP2P.ServicioGestionarAudio);
            mAyudanteVideo    = new AyudanteStream(mParticipanteP2P, mNombreNodo, mParticipanteP2P.ServicioGestionarVideo);
            mAyudanteDescarga = new AyudanteDescarga(mParticipanteP2P.ServicioGestionarDescarga);

            try
            {
                AsyncCallback callBackAsync = new AsyncCallback(AbrirProceso);
                TimeSpan      ts            = new TimeSpan(0, 1, 0);
                mParticipanteP2P.BeginOpen(ts, callBackAsync, this);
            }
            catch (CommunicationException e)
            {
                System.Windows.MessageBox.Show(String.Format("Error al acceder a la red: {0}", e.Message));
                mParticipanteP2P = null;
                return(false);
            }
            return(true);
        }
 protected override void OnApplyConfiguration(Binding binding)
 {
     NetPeerTcpBinding peerBinding = (NetPeerTcpBinding)binding;
     peerBinding.ListenIPAddress = this.ListenIPAddress;
     peerBinding.MaxBufferPoolSize = this.MaxBufferPoolSize;
     peerBinding.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
     peerBinding.Port = this.Port;
     peerBinding.Security = new PeerSecuritySettings();
     this.ReaderQuotas.ApplyConfiguration(peerBinding.ReaderQuotas);
     this.Resolver.ApplyConfiguration(peerBinding.Resolver);
     this.Security.ApplyConfiguration(peerBinding.Security);
 }
Esempio n. 23
0
        private static Binding GetNetPeerTcpBinding()
        {
            var binding = new NetPeerTcpBinding();

            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.Security.Mode          = SecurityMode.None;
            binding.ReaderQuotas.MaxDepth  = int.MaxValue;
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            binding.ReaderQuotas.MaxArrayLength         = int.MaxValue;
            binding.ReaderQuotas.MaxBytesPerRead        = int.MaxValue;
            binding.ReaderQuotas.MaxNameTableCharCount  = int.MaxValue;
            return(binding);
        }
        protected internal override void InitializeFrom(Binding binding)
        {
            base.InitializeFrom(binding);
            NetPeerTcpBinding peerBinding = (NetPeerTcpBinding)binding;
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ListenIPAddress, peerBinding.ListenIPAddress);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBufferPoolSize, peerBinding.MaxBufferPoolSize);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxReceivedMessageSize, peerBinding.MaxReceivedMessageSize);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Port, peerBinding.Port);
            this.Security.InitializeFrom(peerBinding.Security);
            this.Resolver.InitializeFrom(peerBinding.Resolver);

            this.ReaderQuotas.InitializeFrom(peerBinding.ReaderQuotas);
        }
Esempio n. 25
0
        protected internal override void InitializeFrom(Binding binding)
        {
            base.InitializeFrom(binding);
            NetPeerTcpBinding binding2 = (NetPeerTcpBinding)binding;

            this.ListenIPAddress        = binding2.ListenIPAddress;
            this.MaxBufferPoolSize      = binding2.MaxBufferPoolSize;
            this.MaxReceivedMessageSize = binding2.MaxReceivedMessageSize;
            this.Port = binding2.Port;
            this.Security.InitializeFrom(binding2.Security);
            this.Resolver.InitializeFrom(binding2.Resolver);
            this.ReaderQuotas.InitializeFrom(binding2.ReaderQuotas);
        }
Esempio n. 26
0
        internal static void ConfigureNone(Collection <ServiceEndpoint> endpoints)
        {
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                Binding binding = endpoint.Binding;

                if (binding is BasicHttpBinding)
                {
                    BasicHttpBinding basicBinding = (BasicHttpBinding)binding;
                    basicBinding.Security.Mode = BasicHttpSecurityMode.None;
                    continue;
                }
                if (binding is NetTcpBinding)
                {
                    NetTcpBinding tcpBinding = (NetTcpBinding)binding;
                    tcpBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is NetPeerTcpBinding)
                {
                    NetPeerTcpBinding peerBinding = (NetPeerTcpBinding)binding;
                    peerBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is NetNamedPipeBinding)
                {
                    NetNamedPipeBinding pipeBinding = (NetNamedPipeBinding)binding;
                    pipeBinding.Security.Mode = NetNamedPipeSecurityMode.None;
                    continue;
                }
                if (binding is WSHttpBinding)
                {
                    WSHttpBinding wsBinding = (WSHttpBinding)binding;
                    wsBinding.Security.Mode = SecurityMode.None;
                    continue;
                }
                if (binding is WSDualHttpBinding)
                {
                    WSDualHttpBinding wsDualBinding = (WSDualHttpBinding)binding;
                    wsDualBinding.Security.Mode = WSDualHttpSecurityMode.None;
                    continue;
                }
                if (binding is NetMsmqBinding)
                {
                    NetMsmqBinding msmqBinding = (NetMsmqBinding)binding;
                    msmqBinding.Security.Mode = NetMsmqSecurityMode.None;
                    continue;
                }
                throw new InvalidOperationException(binding.GetType() + "is unsupprted with ServiceSecurity.None");
            }
        }
Esempio n. 27
0
        internal static Binding CreateBinding(string flag)
        {
            Binding binding = null;

            switch (flag)
            {
            case "NetTcp":
                binding = new NetTcpBinding();
                break;

            case "BasicHttp":
                binding = new BasicHttpBinding();
                break;

            case "WSHttp":
                binding = new WSHttpBinding();
                break;

            case "WSDualHttp":
                binding = new WSDualHttpBinding();
                break;

            case "WSFederationHttp":
                binding = new WSFederationHttpBinding();
                break;

            case "NetNamedPipe":
                binding = new NetNamedPipeBinding();
                break;

            case "NetMsmq":
                binding = new NetMsmqBinding();
                break;

            case "NetPeerTcp":
                binding = new NetPeerTcpBinding();
                break;

            case "MsmqIntegration":
                binding = new System.ServiceModel.MsmqIntegration.MsmqIntegrationBinding();
                break;

            default:
                binding = new NetTcpBinding();
                break;
            }

            return(binding);
        }
Esempio n. 28
0
        /// <summary>
        /// 根据绑定协议创建具体绑定对象
        /// </summary>
        /// <param name="bindingName"></param>
        /// <returns></returns>
        private static Binding CreateBindingByName(string bindingName)
        {
            Binding binding = null;

            switch (bindingName)
            {
            case BindingName.NetTcpBinding:
                binding = new NetTcpBinding();
                break;

            case BindingName.BasicHttpBinding:
                binding = new BasicHttpBinding();
                break;

            case BindingName.WSHttpBinding:
                binding = new WSHttpBinding();
                break;

            case BindingName.WSDualHttpBinding:
                binding = new WSDualHttpBinding();
                break;

            case BindingName.WSFederationHttpBinding:
                binding = new WSFederationHttpBinding();
                break;

            case BindingName.NetNamedPipeBinding:
                binding = new NetNamedPipeBinding();
                break;

            case BindingName.NetMsmqBinding:
                binding = new NetMsmqBinding();
                break;

            case BindingName.NetPeerTcpBinding:
                binding = new NetPeerTcpBinding();
                break;

            case BindingName.CustomBinding:
                binding = new CustomBinding();
                break;

            default:
                binding = new NetTcpBinding();
                break;
            }
            return(binding);
        }
Esempio n. 29
0
 void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
 {
     if (endpointContext == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext");
     }
     if (endpointContext.Endpoint.Binding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext.Binding");
     }
     if (endpointContext.Endpoint.Binding is CustomBinding)
     {
         System.ServiceModel.Channels.Binding binding;
         BindingElementCollection             elements = ((CustomBinding)endpointContext.Endpoint.Binding).Elements;
         TransportBindingElement element = elements.Find <TransportBindingElement>();
         if (element is HttpTransportBindingElement)
         {
             if (WSHttpBindingBase.TryCreate(elements, out binding))
             {
                 this.SetBinding(endpointContext.Endpoint, binding);
             }
             else if (WSDualHttpBinding.TryCreate(elements, out binding))
             {
                 this.SetBinding(endpointContext.Endpoint, binding);
             }
             else if (BasicHttpBinding.TryCreate(elements, out binding))
             {
                 this.SetBinding(endpointContext.Endpoint, binding);
             }
         }
         else if ((element is MsmqTransportBindingElement) && NetMsmqBinding.TryCreate(elements, out binding))
         {
             this.SetBinding(endpointContext.Endpoint, binding);
         }
         else if ((element is NamedPipeTransportBindingElement) && NetNamedPipeBinding.TryCreate(elements, out binding))
         {
             this.SetBinding(endpointContext.Endpoint, binding);
         }
         else if ((element is PeerTransportBindingElement) && NetPeerTcpBinding.TryCreate(elements, out binding))
         {
             this.SetBinding(endpointContext.Endpoint, binding);
         }
         else if ((element is TcpTransportBindingElement) && NetTcpBinding.TryCreate(elements, out binding))
         {
             this.SetBinding(endpointContext.Endpoint, binding);
         }
     }
 }
Esempio n. 30
0
        private Binding method_1(IBindingConfigurationElement ibindingConfigurationElement_0)
        {
            Binding result;

            if (ibindingConfigurationElement_0 is CustomBindingElement)
            {
                result = new CustomBinding();
            }
            else if (ibindingConfigurationElement_0 is BasicHttpBindingElement)
            {
                result = new BasicHttpBinding();
            }
            else if (ibindingConfigurationElement_0 is NetMsmqBindingElement)
            {
                result = new NetMsmqBinding();
            }
            else if (ibindingConfigurationElement_0 is NetNamedPipeBindingElement)
            {
                result = new NetNamedPipeBinding();
            }
            else if (ibindingConfigurationElement_0 is NetPeerTcpBindingElement)
            {
                result = new NetPeerTcpBinding();
            }
            else if (ibindingConfigurationElement_0 is NetTcpBindingElement)
            {
                result = new NetTcpBinding();
            }
            else if (ibindingConfigurationElement_0 is WSDualHttpBindingElement)
            {
                result = new WSDualHttpBinding();
            }
            else if (ibindingConfigurationElement_0 is WSHttpBindingElement)
            {
                result = new WSHttpBinding();
            }
            else if (ibindingConfigurationElement_0 is WSFederationHttpBindingElement)
            {
                result = new WSFederationHttpBinding();
            }
            else
            {
                result = null;
            }
            return(result);
        }