コード例 #1
0
ファイル: FromAddServer.cs プロジェクト: guldmann/UniSearch
        private void ConnectToServer()
        {
            //default ports
            string NETport = "808";


            if (!string.IsNullOrEmpty(textBoxNetTcpPort.Text))
            {
                NETport = textBoxNetTcpPort.Text;
            }

            IndexServiceClient proxy = new IndexServiceClient();

            proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
                X509CertificateValidationMode.None;
            proxy.ClientCredentials.UserName.UserName = textBoxUserName.Text;
            proxy.ClientCredentials.UserName.Password = textBoxPassword.Text;

            string NETUrl = "net.tcp://" + textBoxURL.Text + ":" + NETport + "/IndexService";

            string dnsIdentity = null; // use localhost for test certificate

            if (!string.IsNullOrEmpty(textBoxCertDomain.Text))
            {
                dnsIdentity = textBoxCertDomain.Text;
            }
            else
            {
                dnsIdentity = textBoxURL.Text;
            }

            EndpointIdentity identity = EndpointIdentity.CreateDnsIdentity(dnsIdentity);

            proxy.Endpoint.Address = new EndpointAddress(new Uri(NETUrl), identity);

            try
            {
                proxy.Open();
                proxy.GetIndexStatus();
                MessageBox.Show("Connection OK.");
                proxy.Close();
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    MessageBox.Show(e.InnerException.Message + Environment.NewLine + e.Message);
                }
                else
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //TODO :  add this to a list
            Server server = new Server
            {
                name     = "localhost",
                port     = "808",
                userName = "******",
                passWord = "******",
                url      = "net.tcp://localhost/IndexService" /// dela upp denna strängen
            };

            IndexServiceClient proxy = new IndexServiceClient();

            proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
                X509CertificateValidationMode.None;
            proxy.ClientCredentials.UserName.UserName = server.userName;
            proxy.ClientCredentials.UserName.Password = server.passWord;

            proxy.Endpoint.Address = new EndpointAddress(new Uri(server.url));
            try
            {
                proxy.Open();
                if (!proxy.GetIndexStatus())
                {
                    MessageBox.Show("Server is not ready");
                }
                else
                {
                    var startTime = DateTime.Now;
                    var result    = proxy.Search(textBoxName.Text, textBoxExtension.Text);
                    List <IndexServiceReference.IndexFile> lst =
                        result.OfType <IndexServiceReference.IndexFile>().ToList();
                    var resultTime = (DateTime.Now - startTime);
                    labelSearchTimeValue.Text = resultTime.TotalMilliseconds + "millisec";
                    PopulateListView(lst);
                    labelFilesValue.Text = lst.Count.ToString();
                }

                proxy.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed: " + ex.Message);
            }
        }