Exemplo n.º 1
0
        private void StartService()
        {
            try
            {
                //Address
                string hostName = Dns.GetHostName();
                urlService = "net.tcp://" + hostName.ToString() + ":8000/MyService";
                host = new ServiceHost(typeof(BShipServiceLib.BShipServiceClass));

                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

                //Binding - add endpoint
                host.AddServiceEndpoint(typeof(BShipServiceLib.IBShipService), tcpBinding, urlService);

                //Channel
                ServiceMetadataBehavior metadataBehavior;
                metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
                if (metadataBehavior == null)
                {
                    //Gonna remove the app.config file by doing this, enabling meta data
                    metadataBehavior = new ServiceMetadataBehavior();
                    metadataBehavior.HttpGetUrl = new Uri("http://" + hostName.ToString() + ":8001/MyService");
                    metadataBehavior.HttpGetEnabled = true;
                    metadataBehavior.ToString();
                    host.Description.Behaviors.Add(metadataBehavior);
                    urlMeta = metadataBehavior.HttpGetUrl.ToString();
                }

                host.Open();
            }
            catch (Exception ex) { }
        }
Exemplo n.º 2
0
        private void ConfigureService()
        {
            // Returns a list of ipaddress configuration
            IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress ipAddress = ips.AddressList[0]; // Select the first entry. I hope it's this maschines IP
            
            // Create the url that is needed to specify where the service should be started
            urlService = "net.tcp://" + ipAddress + ":8000/AlarmServer";
            host = new ServiceHost(typeof(AlarmServer));

            NetTcpBinding tcpBinding = new NetTcpBinding();
            tcpBinding.TransactionFlow = false;
            tcpBinding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
            tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            tcpBinding.Security.Mode = SecurityMode.None;
            // <- Very crucial

            // Add a endpoint
            host.AddServiceEndpoint(typeof(IAlarmServer), 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/AlarmServer");
                metadataBehavior.HttpGetEnabled = true;
                metadataBehavior.ToString();
                host.Description.Behaviors.Add(metadataBehavior);
                urlMeta = metadataBehavior.HttpGetUrl.ToString();
            }

            //forProxy
            //host.AddServiceEndpoint(typeof(AlarmServer), )
            host.Open();
        }