Esempio n. 1
0
        private void upLoadPhoto_Click(object sender, EventArgs e)
        {
            Common.SslServerCertificateValidator certValidator = new Common.SslServerCertificateValidator();

            CommercialVehicleCollisionPortTypeClient client = null;

            using (UserCredentialsDialog dialog = new UserCredentialsDialog())
            {
                dialog.Caption = "Connect to the WSC Service";
                dialog.Message = "Enter your credentials";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    if (dialog.SaveChecked)
                    {
                        dialog.ConfirmCredentials(true);
                    }

                    client = new CommercialVehicleCollisionPortTypeClient("CommercialVehicleCollisionFrontendService");
              
                    client.ClientCredentials.UserName.UserName = dialog.User;
                    client.ClientCredentials.UserName.Password = dialog.PasswordToString();

                    client.Endpoint.Binding.SendTimeout = TimeSpan.FromMinutes(30);
                    client.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromMinutes(30);

                    // New symmetric binding over transport

                    // HA50IDP
                    //client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.TrustedPeople,
                    //    X509FindType.FindByThumbprint, "65 c7 27 37 93 8a 2f 24 4b 77 ff 72 0a 2a ed 48 4b 26 ef 82");

                    // CUREIDP
                    //client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.TrustedPeople,
                    //    X509FindType.FindByThumbprint, "a8 3a f6 ad f6 cd 7d f3 bf ca 5f 23 26 15 8f 7e ad 37 8b 66");

                    try
                    {
                        // Use the 'client' variable to call operations on the service.
                        ResultListBox.Items.Clear();

                        string imageFile = "CommercialVehicleCollisionClient.Net.jpg";
                        byte[] photoUpload = OpenImage(imageFile);
                        string photoId = client.uploadPhoto(photoUpload);
                                                
                        ResultListBox.Visible = true;
                        ResultListBox.Items.Add("photoId: " + photoId);           
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                        if (ex.InnerException != null)
                        {
                            Console.WriteLine("\tInner Error: " + ex.InnerException.Message);
                        }

                        client.Abort();
                    }
                    finally
                    {
                        client.Close();
                    }
                }
            }
        }
Esempio n. 2
0
        private void downloadData_Click(object sender, EventArgs e)
        {
            Common.SslServerCertificateValidator certValidator = new Common.SslServerCertificateValidator();

            CommercialVehicleCollisionPortTypeClient client = null;

            using (UserCredentialsDialog dialog = new UserCredentialsDialog())
            {
                dialog.Caption = "Connect to the WSC Service";
                dialog.Message = "Enter your credentials";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    if (dialog.SaveChecked)
                    {
                        dialog.ConfirmCredentials(true);
                    }

                    client = new CommercialVehicleCollisionPortTypeClient("CommercialVehicleCollisionFrontendService");

                    client.ClientCredentials.UserName.UserName = dialog.User;
                    client.ClientCredentials.UserName.Password = dialog.PasswordToString();

                    client.Endpoint.Binding.SendTimeout = TimeSpan.FromMinutes(30);
                    client.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromMinutes(30);

                    try
                    {
                        ResultListBox.Items.Clear();

                        // download the file
                        int size = 20000000;
                        byte[] photoDownload = client.downloadData(size);
                                        
                        ResultListBox.Visible = true;

                        ResultListBox.Items.Add("Download size = " + photoDownload.Length);
                        
                        byte[] data = photoDownload;

                        MemoryStream memStream = new MemoryStream(data);

                        byte[] buffer = new byte[8192];

                        int len = 0;

                        int total = 0;
                        while ((len = memStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            for (int i = 0; i < len; i++)
                            {
                                if (buffer[i] != (byte)('A' + (total + i) % 26))
                                {
                                    ResultListBox.Items.Add("\tFAIL: Generated data is different");
                                }
                            }

                            total += len;
                        }

                        if (size != data.Length)
                        {
                            ResultListBox.Items.Add("\tFAIL: Generated data is different SIZE");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                        if (ex.InnerException != null)
                        {
                            Console.WriteLine("\tInner Error: " + ex.InnerException.Message);
                        }
                    }
                    finally
                    {
                        client.Close();
                    }
                }
            }
        }
Esempio n. 3
0
        private void GetDocument_Click(object sender, EventArgs e)
        {
            Common.SslServerCertificateValidator certValidator = new Common.SslServerCertificateValidator();

            CommercialVehicleCollisionPortTypeClient client = null;

            using (UserCredentialsDialog dialog = new UserCredentialsDialog())
            {
                dialog.Caption = "Connect to the WSC Service";
                dialog.Message = "Enter your credentials";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    if (dialog.SaveChecked)
                    {
                        dialog.ConfirmCredentials(true);
                    }

                    client = new CommercialVehicleCollisionPortTypeClient("CommercialVehicleCollisionFrontendService");


                    ////Set the Custom IdentityVerifier
                    //ssbe.LocalClientSettings.IdentityVerifier = new Common.CustomIdentityVerifier();

                    client.Endpoint.Binding.SendTimeout = TimeSpan.FromMinutes(30);
                    client.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromMinutes(30);

                    client.ClientCredentials.UserName.UserName = dialog.User;
                    client.ClientCredentials.UserName.Password = dialog.PasswordToString();
                                        
                    // HA50IDP
                    //client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.TrustedPeople,
                    //    X509FindType.FindByThumbprint, "65 c7 27 37 93 8a 2f 24 4b 77 ff 72 0a 2a ed 48 4b 26 ef 82");

                    // CUREIDP
                    //client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.TrustedPeople,
                    //    X509FindType.FindByThumbprint, "a8 3a f6 ad f6 cd 7d f3 bf ca 5f 23 26 15 8f 7e ad 37 8b 66");
                    
                    try
                    {
                        ResultListBox.Items.Clear();

                        // Use the 'client' variable to call operations on the service.
                        CommercialVehicleCollisionDocumentType doc = client.getDocument("AnId\tANother line");

                        
                        ResultListBox.Visible = true;
                        ResultListBox.Items.Add("DocID: " + doc.DocumentFileControlID);
                        
                        ResultListBox.Items.Add("Incident Text: " + doc.IncidentText);

                        foreach (string vin in doc.InvolvedVehicleVIN)
                        {
                            ResultListBox.Items.Add("Vehicle VIN: " + vin);
                        }                                                
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.Message);
                        if (ex.InnerException != null)
                        {
                            Console.WriteLine("\tInner Error: " + ex.InnerException.Message);
                        }

                        client.Abort();
                    }
                    finally
                    {
                        client.Close();
                    }
                }
            }
        }