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