Ejemplo n.º 1
0
        private void Register_RegisterClicked(object sender, RoutedEventArgs e)
        {
            NetTcpBinding serviceBinding = new NetTcpBinding(SecurityMode.None);
            serviceBinding.ReceiveTimeout = TimeSpan.MaxValue;
            serviceBinding.SendTimeout = TimeSpan.MaxValue;
            proxy = DuplexChannelFactory<ITableService>.CreateChannel(this, serviceBinding, new EndpointAddress(Properties.Settings.Default.ServerAddress));

            TcpTransportBindingElement transport = new TcpTransportBindingElement();
            transport.MaxReceivedMessageSize = long.MaxValue;
            transport.MaxBufferSize = int.MaxValue;
            transport.MaxBufferPoolSize = long.MaxValue;
            transport.TransferMode = TransferMode.Streamed;

            BinaryMessageEncodingBindingElement encoder = new BinaryMessageEncodingBindingElement();
            CustomBinding fileBinding = new CustomBinding(encoder, transport);
            fileBinding.ReceiveTimeout = TimeSpan.MaxValue;
            fileBinding.SendTimeout = TimeSpan.MaxValue;
            fileProxy = ChannelFactory<IFileDownloadService>.CreateChannel(fileBinding, new EndpointAddress(Properties.Settings.Default.FileServerAddress));

            try
            {
                DateTime serverTime = proxy.GetTime();
                OffsetDateTime.Difference = serverTime - DateTime.UtcNow;

                proxy.Register(currentUser);
            }
            catch (FaultException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (EndpointNotFoundException)
            {
                MessageBox.Show("Could not connect to the table");
            }
            finally
            {
                Register r = (Register)sender;
                r.RegisterButton.Visibility = Visibility.Visible;
                r.Spinner.Visibility = Visibility.Collapsed;
            }
        }