Esempio n. 1
0
        void OpenService()
        {
            try
            {
                string       ipAddress             = "10.0.0.17";
                const string MegaPopServerRegistry = "SOFTWARE\\Eli\\ChatServer";
                clsRegistry  reg = new clsRegistry();
                ipAddress = reg.GetStringValue(Registry.LocalMachine, MegaPopServerRegistry, "LocalIpAddress");



                // Create the url that is needed to specify
                // where the service should be started
                urlService = "net.tcp://" + ipAddress + ":8099/ChatService";

                // Instruct the ServiceHost that the type
                // that is used is a ServiceLibrary.service1
                host          = new ServiceHost(typeof(ChatService));
                host.Opening += new EventHandler(host_Opening);
                host.Opened  += new EventHandler(host_Opened);
                host.Closing += new EventHandler(host_Closing);
                host.Closed  += new EventHandler(host_Closed);

                // The binding is where we can choose what
                // transport layer we want to use. HTTP, TCP ect.
                NetTcpBinding tcpBinding = new NetTcpBinding();
                tcpBinding.TransactionFlow = false;
                tcpBinding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;
                tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                tcpBinding.Security.Mode = SecurityMode.Transport;
                // <- Very crucial

                // Add a endpoint
                host.AddServiceEndpoint(typeof(ChatServiceLib.IChatService), tcpBinding, urlService);

                // A channel to describe the service.
                // Used with the proxy scvutil.exe tool
                ServiceMetadataBehavior metadataBehavior;
                metadataBehavior =
                    host.Description.Behaviors.Find <ServiceMetadataBehavior>();

                if (metadataBehavior == null)
                {
                    // This is how I create the proxy object
                    // that is generated via the svcutil.exe tool
                    metadataBehavior                = new ServiceMetadataBehavior();
                    metadataBehavior.HttpGetUrl     = new Uri("http://" + ipAddress + ":8002/ChatService");
                    metadataBehavior.HttpGetEnabled = true;
                    metadataBehavior.ToString();
                    host.Description.Behaviors.Add(metadataBehavior);
                    urlMeta = metadataBehavior.HttpGetUrl.ToString();
                }
                host.Open();
            }
            catch (Exception err)
            {
                File.AppendAllText("c:\\chatwcf.txt", err.Message + Environment.NewLine);
            }
        }
Esempio n. 2
0
        public void StartService(string ipaddress, int port)
        {
            try
            {
                // Create the url that is needed to specify where the service should be started
                urlService    = "net.tcp://" + ipaddress + ":" + port + "/MyService";
                host          = new ServiceHost(typeof(ServiceLibrary.service1));
                host.Opening += new EventHandler(host_Opening);
                host.Opened  += new EventHandler(host_Opened);
                host.Closing += new EventHandler(host_Closing);
                host.Closed  += new EventHandler(host_Closed);

                // The binding is where we can choose what
                // transport layer we want to use. HTTP, TCP ect.
                NetTcpBinding tcpBinding = new NetTcpBinding();
                tcpBinding.TransactionFlow = false;
                tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

                int x = tcpBinding.MaxConnections;
                tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;


                //tcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 5);
                tcpBinding.SendTimeout = new TimeSpan(0, 0, 5);
                //tcpBinding.OpenTimeout = new TimeSpan(0, 0, 2);
                //tcpBinding.CloseTimeout = new TimeSpan(0, 0, 2);
                tcpBinding.Security.Mode = SecurityMode.Transport;
                // <- Very crucial

                // Add a endpoint
                host.AddServiceEndpoint(typeof(ServiceLibrary.IService1), tcpBinding, urlService);

                // A channel to describe the service.
                // Used with the proxy scvutil.exe tool
                ServiceMetadataBehavior metadataBehavior;
                metadataBehavior =
                    host.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (metadataBehavior == null)
                {
                    // This is how I create the proxy object
                    // that is generated via the svcutil.exe tool
                    metadataBehavior                = new ServiceMetadataBehavior();
                    metadataBehavior.HttpGetUrl     = new Uri("http://" + ipaddress + ":" + (port + 1) + "/MyService");
                    metadataBehavior.HttpGetEnabled = true;
                    metadataBehavior.ToString();
                    host.Description.Behaviors.Add(metadataBehavior);
                    urlMeta = metadataBehavior.HttpGetUrl.ToString();
                }

                host.Open();
            }
            catch (Exception err)
            {
                throw (new SystemException(err.Message));
            }
        }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                IPHostEntry
                    ips = Dns.GetHostEntry(Dns.GetHostName());

                IPAddress
                    _ipAddress = ips.AddressList[0];

                urlService = "net.tcp://" + _ipAddress.ToString() + ":8000/EvalService";

                host          = new ServiceHost(typeof(EvalServiceLibrary.EvalService));
                host.Opening += new EventHandler(host_Opening);
                host.Opened  += new EventHandler(host_Opened);
                host.Closing += new EventHandler(host_Closing);
                host.Closed  += new EventHandler(host_Closed);

                NetTcpBinding
                    tcpBinding = new NetTcpBinding();

                tcpBinding.TransactionFlow = false;
                tcpBinding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;
                tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                tcpBinding.Security.Mode = SecurityMode.None; // <- Very crucial

                host.AddServiceEndpoint(typeof(EvalServiceLibrary.IEvalService), tcpBinding, urlService);

                ServiceMetadataBehavior
                    metadataBehavior;

                metadataBehavior = host.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (metadataBehavior == null)
                {
                    metadataBehavior                = new ServiceMetadataBehavior();
                    metadataBehavior.HttpGetUrl     = new Uri("http://" + _ipAddress.ToString() + ":8001/EvalService");
                    metadataBehavior.HttpGetEnabled = true;
                    metadataBehavior.ToString();
                    host.Description.Behaviors.Add(metadataBehavior);
                    urlMeta = metadataBehavior.HttpGetUrl.ToString();
                }

                host.Open();
            }
            catch (Exception eException)
            {
                Append(string.Format("{1}{0}Message: \"{2}\"{3}{0}StackTrace:{0}{4}",
                                     Environment.NewLine,
                                     eException.GetType().FullName,
                                     eException.Message,
                                     eException.InnerException != null ? Environment.NewLine + "InnerException.Message: \"" + eException.InnerException.Message + "\"" : string.Empty,
                                     eException.StackTrace));
            }
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // Returns a list of ipaddress configuration
                IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName());

                // Select the first entry. I hope it's this maschines IP
                IPAddress _ipAddress = ips.AddressList[0];

                string ipaddress = "192.168.26.16";
                // Create the url that is needed to specify where the service should be started
                urlService = "net.tcp://" + ipaddress + ":8030/MyService";

                // Instruct the ServiceHost that the type that is used is a ServiceLibrary.service1
                host          = new ServiceHost(typeof(ServiceLibrary.service1));
                host.Opening += new EventHandler(host_Opening);
                host.Opened  += new EventHandler(host_Opened);
                host.Closing += new EventHandler(host_Closing);
                host.Closed  += new EventHandler(host_Closed);


                // The binding is where we can choose what transport layer we want to use. HTTP, TCP ect.
                NetTcpBinding tcpBinding = new NetTcpBinding();
                tcpBinding.TransactionFlow = false;
                tcpBinding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;
                tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                tcpBinding.Security.Mode = SecurityMode.None; // <- Very crucial

                // Add a endpoint
                host.AddServiceEndpoint(typeof(ServiceLibrary.IService1), tcpBinding, urlService);

                // A channel to describe the service. Used with the proxy scvutil.exe tool
                ServiceMetadataBehavior metadataBehavior;
                metadataBehavior = host.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (metadataBehavior == null)
                {
                    // This is how I create the proxy object that is generated via the svcutil.exe tool
                    metadataBehavior                = new ServiceMetadataBehavior();
                    metadataBehavior.HttpGetUrl     = new Uri("http://" + ipaddress + ":8001/MyService");
                    metadataBehavior.HttpGetEnabled = true;
                    metadataBehavior.ToString();
                    host.Description.Behaviors.Add(metadataBehavior);
                    urlMeta = metadataBehavior.HttpGetUrl.ToString();
                }

                host.Open();
            }
            catch (Exception ex1)
            {
                Append(ex1.StackTrace);
            }
        }
Esempio n. 5
0
        protected override void OnStart(string[] args)
        {
            host = new ServiceHost(typeof(HAP.Data.Quota.WCFService));
            string urlService = "net.tcp://" + Dns.GetHostName() + ":8010/HAPQuotaService";

            // Instruct the ServiceHost that the type

            // The binding is where we can choose what

            // transport layer we want to use. HTTP, TCP ect.

            NetTcpBinding tcpBinding = new NetTcpBinding();

            tcpBinding.TransactionFlow = false;
            tcpBinding.Security.Transport.ProtectionLevel =
                System.Net.Security.ProtectionLevel.EncryptAndSign;
            tcpBinding.Security.Transport.ClientCredentialType =
                TcpClientCredentialType.Windows;
            tcpBinding.Security.Mode = SecurityMode.None;
            // <- Very crucial


            // Add a endpoint

            host.AddServiceEndpoint(typeof(HAP.Data.Quota.IService), tcpBinding, urlService);

            // A channel to describe the service.

            // Used with the proxy scvutil.exe tool
            string urlMeta = "";

            ServiceMetadataBehavior metadataBehavior;

            metadataBehavior =
                host.Description.Behaviors.Find <ServiceMetadataBehavior>();
            if (metadataBehavior == null)
            {
                // This is how I create the proxy object

                // that is generated via the svcutil.exe tool

                metadataBehavior                = new ServiceMetadataBehavior();
                metadataBehavior.HttpGetUrl     = new Uri("http://" + Dns.GetHostName() + ":8011/HAPQuotaService");
                metadataBehavior.HttpGetEnabled = true;
                metadataBehavior.ToString();
                host.Description.Behaviors.Add(metadataBehavior);
                urlMeta = metadataBehavior.HttpGetUrl.ToString();
            }

            host.Open();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            try
            {
                /*
                 * // test code for the queue...
                 * QueueBaseFileListWriter q = new QueueBaseFileListWriter(10, "writeList\\");
                 * QueueBaseFileListReader q1 = new QueueBaseFileListReader(10, "readList\\", "writeList\\");
                 * ulong listNum;
                 * ulong fileNumber;
                 * bool copyStatus;
                 * for (int i = 0; i < 20; i++)
                 * {
                 *  q.AddFile("eee");
                 *  Console.WriteLine(q1.GetFile(out listNum, out fileNumber, out copyStatus));
                 *  //q1.MarkAsSent();
                 * }
                 */
                _handler += new _EventHandler(Handler);
                SetConsoleCtrlHandler(_handler, true);

                int             port      = 8030;
                NetCard.NetCard n         = new NetCard.NetCard();
                string          ipaddress = n.getComputerIP();
                Console.WriteLine("Listening on ip address: " + ipaddress);
                // Create the url that is needed to specify where the service should be started
                urlService = "net.tcp://" + ipaddress + ":" + port + "/MyService";
                //host = new ServiceHost(typeof(ServiceLibrary.service1));
                host = new ServiceHost(m_Instance, new Uri(urlService));

                host.Opening += new EventHandler(host_Opening);
                host.Opened  += new EventHandler(host_Opened);
                host.Closing += new EventHandler(host_Closing);
                host.Closed  += new EventHandler(host_Closed);

                // The binding is where we can choose what
                // transport layer we want to use. HTTP, TCP ect.
                NetTcpBinding tcpBinding = new NetTcpBinding();
                tcpBinding.TransactionFlow = false;
                tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

                int x = tcpBinding.MaxConnections;
                tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;


                //tcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 5);
                tcpBinding.SendTimeout   = new TimeSpan(0, 0, 5);
                tcpBinding.OpenTimeout   = new TimeSpan(0, 0, 10);
                tcpBinding.CloseTimeout  = new TimeSpan(0, 0, 2);
                tcpBinding.Security.Mode = SecurityMode.Transport;
                // <- Very crucial

                // Add a endpoint
                host.AddServiceEndpoint(typeof(ServiceLibrary.IService), tcpBinding, urlService);

                // A channel to describe the service.
                // Used with the proxy scvutil.exe tool
                ServiceMetadataBehavior metadataBehavior;
                metadataBehavior =
                    host.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (metadataBehavior == null)
                {
                    // This is how I create the proxy object
                    // that is generated via the svcutil.exe tool
                    metadataBehavior                = new ServiceMetadataBehavior();
                    metadataBehavior.HttpGetUrl     = new Uri("http://" + ipaddress + ":" + (port + 1) + "/MyService");
                    metadataBehavior.HttpGetEnabled = true;
                    metadataBehavior.ToString();
                    host.Description.Behaviors.Add(metadataBehavior);
                    urlMeta = metadataBehavior.HttpGetUrl.ToString();
                }

                host.Open();
                m_open = true;
                Console.WriteLine("WCF Streaming Client on field Service is opened");
                Console.ReadLine();
                (m_Instance as ServiceLibrary.service1).CloseService();
                host.Close();
                m_open = false;
            }
            catch (Exception err)
            {
                throw (new SystemException(err.Message));
            }
        }