static void Main() { // Create a proxy with given client endpoint configuration using (CalculatorProxy proxy = new CalculatorProxy()) { // Call the Add service operation. double value1 = 100.00D; double value2 = 15.99D; double result = proxy.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation. value1 = 145.00D; value2 = 76.54D; result = proxy.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation. value1 = 9.00D; value2 = 81.25D; result = proxy.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation. value1 = 22.00D; value2 = 7.00D; result = proxy.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); } Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client."); Console.ReadLine(); }
static void Main() { // Get the username and password Console.WriteLine("Username authentication required."); Console.WriteLine("Provide a username."); Console.WriteLine(" Enter username: (test1)"); string username = Console.ReadLine(); Console.WriteLine(" Enter password:"******""; ConsoleKeyInfo info = Console.ReadKey(true); while (info.Key != ConsoleKey.Enter) { if (info.Key != ConsoleKey.Backspace) { if (info.KeyChar != '\0') { password += info.KeyChar; } info = Console.ReadKey(true); } else if (info.Key == ConsoleKey.Backspace) { if (password != "") { password = password.Substring(0, password.Length - 1); } info = Console.ReadKey(true); } } for (int i = 0; i < password.Length; i++) { Console.Write("*"); } Console.WriteLine(); // Create a proxy with Username endpoint configuration CalculatorProxy proxy = new CalculatorProxy("Username"); try { proxy.ClientCredentials.UserName.UserName = username; proxy.ClientCredentials.UserName.Password = password; // Call the Add service operation. double value1 = 100.00D; double value2 = 15.99D; double result = proxy.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation. value1 = 145.00D; value2 = 76.54D; result = proxy.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation. value1 = 9.00D; value2 = 81.25D; result = proxy.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation. value1 = 22.00D; value2 = 7.00D; result = proxy.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); proxy.Close(); } catch (TimeoutException e) { Console.WriteLine("Call timed out : {0}", e.Message); proxy.Abort(); } catch (Exception e) { Console.WriteLine("Call failed:"); while (e != null) { Console.WriteLine("\t{0}", e.Message); e = e.InnerException; } proxy.Abort(); } Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client."); Console.ReadLine(); }
static void Main() { TraceSource ts = new TraceSource("ClientCalculatorTraceSource"); // Start the calculator activity Guid newGuid = Guid.NewGuid(); Trace.CorrelationManager.ActivityId = newGuid; ts.TraceEvent(TraceEventType.Start, 0, "Calculator Activity"); // Create a proxy with given client endpoint configuration using (CalculatorProxy proxy = new CalculatorProxy()) { // Save the calculator activity id to transfer back and forth from/to it Guid originalGuid = Trace.CorrelationManager.ActivityId; // Create and start the Add activity // Generate a new activity id newGuid = Guid.NewGuid(); // Transfer from the calculator activity to the new (Add) activity // The value for the "from" in the transfer is implicit; it is the activity id // previously set in Trace.CorrelationManager.ActivityId // The value for the "to" is explicitly passed as the newGuid parameter ts.TraceTransfer(0, "Transferring...", newGuid); // Set the new activity id in Trace.CorrelationManager.ActivityId; it is now in scope // for subsequently emitted traces Trace.CorrelationManager.ActivityId = newGuid; // Emit the Start trace for the new activity ts.TraceEvent(TraceEventType.Start, 0, "Add Activity"); // Now make the Add request double value1 = 100.00D; double value2 = 15.99D; ts.TraceEvent(TraceEventType.Information, 0, "Client sends Add request message."); double result = proxy.Add(value1, value2); // Trace that you have received the response ts.TraceEvent(TraceEventType.Information, 0, "Client receives Add response message."); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Transfer back to the Calculator activity and stop the current activity ts.TraceTransfer(667, "Transferring...", originalGuid); ts.TraceEvent(TraceEventType.Stop, 0, "Add Activity"); // Set the calculator activity back in scope Trace.CorrelationManager.ActivityId = originalGuid; // Call the Subtract service operation newGuid = Guid.NewGuid(); ts.TraceTransfer(0, "Transferring...", newGuid); Trace.CorrelationManager.ActivityId = newGuid; ts.TraceEvent(TraceEventType.Start, 0, "Subtract Activity"); value1 = 100.00D; value2 = 15.99D; ts.TraceEvent(TraceEventType.Information, 0, "Client sends Subtract request message."); result = proxy.Subtract(value1, value2); ts.TraceEvent(TraceEventType.Information, 0, "Client receives Subtract response message."); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); ts.TraceTransfer(667, "Transferring...", originalGuid); ts.TraceEvent(TraceEventType.Stop, 0, "Subtract Activity"); Trace.CorrelationManager.ActivityId = originalGuid; // Call the Multiply service operation newGuid = Guid.NewGuid(); ts.TraceTransfer(0, "Transferring...", newGuid); Trace.CorrelationManager.ActivityId = newGuid; ts.TraceEvent(TraceEventType.Start, 0, "Multiply Activity"); value1 = 100.00D; value2 = 15.99D; ts.TraceEvent(TraceEventType.Information, 0, "Client sends Multiply request message."); result = proxy.Multiply(value1, value2); ts.TraceEvent(TraceEventType.Information, 0, "Client receives Multiply response message."); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); ts.TraceTransfer(667, "Transferring...", originalGuid); ts.TraceEvent(TraceEventType.Stop, 0, "Multiply Activity"); Trace.CorrelationManager.ActivityId = originalGuid; // Call the Divide service operation newGuid = Guid.NewGuid(); ts.TraceTransfer(0, "Transferring...", newGuid); Trace.CorrelationManager.ActivityId = newGuid; ts.TraceEvent(TraceEventType.Start, 0, "Divide Activity"); value1 = 100.00D; value2 = 15.99D; ts.TraceEvent(TraceEventType.Information, 0, "Client sends Divide request message."); result = proxy.Divide(value1, value2); ts.TraceEvent(TraceEventType.Information, 0, "Client receives Divide response message."); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); ts.TraceTransfer(667, "Transferring...", originalGuid); ts.TraceEvent(TraceEventType.Stop, 0, "Divide Activity"); Trace.CorrelationManager.ActivityId = originalGuid; } ts.TraceEvent(TraceEventType.Stop, 0, "Calculator Activity"); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client."); Console.ReadLine(); }