Esempio n. 1
0
        static void Main(string[] args)
        {
            CommercialVehicleCollisionPortTypeClient client = null;

            try
            {
                //string result = "Random String ";

                //return result;

                // WSP Client Proxy
                //MasterHelloWorldClient client = new MasterHelloWorldClient();

                // Use the 'client' variable to call operations on the service.
                //result = client.HelloWorld(result);

                System.Net.ServicePointManager.ServerCertificateValidationCallback
                    += new System.Net.Security.RemoteCertificateValidationCallback(ServiceCertificateValidator);

                //client = new CommercialVehicleCollisionPortTypeClient("CommercialVehicleCollisionWebservice.CommercialVehicleCollisionPortType-HTTPS");
                client = new CommercialVehicleCollisionPortTypeClient("Standard-ws2007HttpBinding");
                
                client.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;
                
                //System.ServiceModel.Description.ContractDescription cd = client.Endpoint.Contract;
                //cd.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;


                // This needs to be done here since the identityVerifier applies to the client
                WspCustomSecuredBinding binding = client.Endpoint.Binding as WspCustomSecuredBinding;

                if (binding != null)
                {
                    SecurityBindingElement sbe = (SecurityBindingElement)binding.SecurityBindingElement;
                    if (sbe != null)
                    {
                        sbe.LocalClientSettings.IdentityVerifier = new CustomIdentityVerifier();
                    }
                }

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

                Console.WriteLine("DocID: " + doc.DocumentFileControlID);
                Console.WriteLine("Incident Text: " + doc.IncidentText);

                foreach (string vin in doc.InvolvedVehicleVIN)
                {
                    Console.WriteLine("Vehicle VIN: " + vin);
                }


                //// Upload a file
                //string imageFile = "C:\\temp\\MtomFile\\java.jpg";
                //byte[] photoUpload = OpenImage(imageFile);

                //string photoId = client.uploadPhoto(photoUpload);


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

                //Console.WriteLine("\tDownload size = " + photoDownload.Length);


                //byte[] data = photoDownload;
                ////byte[] data = RandomBuffer(size);

                //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))
                //        {
                //            Console.WriteLine("\tFAIL: Generated data is different");
                //        }
                //    }

                //    total += len;
                //}

                //if (size != data.Length)
                //{
                //    Console.WriteLine("\tFAIL: Generated data is different SIZE");
                //}

                //SaveImage("C:\\temp\\MtomFile\\javaDload.jpg", photoDownload);


                Console.WriteLine("\n\nPress Any Key to end...");
                Console.ReadKey();

                // Always close the client.
                //client.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine("\tInner Error: " + e.InnerException.Message);
                }
            }
            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();
                    }
                }
            }
        }
Esempio n. 4
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. 5
0
        static void Main(string[] args)
        {
            CommercialVehicleCollisionPortTypeClient client = null;

            try
            {

                // Wrap this inside a PermissiveCErtificatePolicy or similar class 
                System.Net.ServicePointManager.ServerCertificateValidationCallback
                    += new System.Net.Security.RemoteCertificateValidationCallback(ServiceCertificateValidator);

                string endpointName = ConfigurationManager.AppSettings["EndPointName"];

                client = new CommercialVehicleCollisionPortTypeClient(endpointName);

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

                Console.WriteLine("DocID: " + doc.DocumentFileControlID);
                Console.WriteLine("Incident Text: " + doc.IncidentText);

                foreach (string vin in doc.InvolvedVehicleVIN)
                {
                    Console.WriteLine("Vehicle VIN: " + vin);
                }

                Console.WriteLine("Press a key...");
                Console.ReadKey();


                // Upload a file
                Console.WriteLine("\nUpload File");

                string imageFile = "WebServiceConsumer.Net.jpg";
                byte[] photoUpload = OpenImage(imageFile);

                string photoId = client.uploadPhoto(photoUpload);

                Console.WriteLine("photoId: " + photoId);

                Console.WriteLine("Press a key...");
                Console.ReadKey();
                

                // download binary data
                
                int size = 20000000;
                byte[] photoDownload = client.downloadData(size);

                Console.WriteLine("\tDownload 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))
                        {
                            Console.WriteLine("\tFAIL: Generated data is different");
                            break;
                        }
                    }

                    total += len;
                }

                if (size != data.Length)
                {
                    Console.WriteLine("\tFAIL: Generated data SIZE is different");
                }
                else
                {
                    Console.WriteLine("Download Test Passed.");
                }

                Console.WriteLine("Press a key...");
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine("\tInner Error: " + e.InnerException.Message);
                }

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