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(); } } } }
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(); } }