static void Main(string[] args) { var ServiceHost = new ServiceHost(typeof(CalculatorService)); ServiceHost.Open(); var Client = new CalculatorServiceClient(); try { //Client.Divide(1, 0); var Result = Client.WeighPickle(new Pickle { Name = "Bob", Bumps = 12 }); Console.WriteLine(Result); Client.Close(); } catch (Exception) { Client.Abort(); throw; } Console.ReadLine(); }
static void InvokeCalculatorService(EndpointAddress endpointAddress) { // Create a client CalculatorServiceClient client = new CalculatorServiceClient(new NetTcpBinding(), endpointAddress); Console.WriteLine("Invoking CalculatorService at {0}", endpointAddress.Uri); Console.WriteLine(); double value1 = 100.00D; double value2 = 15.99D; // Call the Add service operation. double result = client.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation. result = client.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation. result = client.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation. result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); Console.WriteLine(); // Closing the client gracefully closes the connection and cleans up resources client.Close(); }
static void InvokeCalculatorService() { // Create a client CalculatorServiceClient client = new CalculatorServiceClient("calculatorEndpoint"); Console.WriteLine("Invoking CalculatorService"); double value1 = 100.00D; double value2 = 15.99D; // Call the Add service operation. double result = client.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation. result = client.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation. result = client.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation. result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); Console.WriteLine(); //Closing the client gracefully closes the connection and cleans up resources client.Close(); }
public static void Main() { try { // Instantiate the client with a CustomBinding which has DiscoveryClientBindingElement CalculatorServiceClient client = new CalculatorServiceClient( CreateCustomBindingWithDiscoveryElement(), DiscoveryClientBindingElement.DiscoveryEndpointAddress); Console.WriteLine("Discovering and invoking CalculatorService."); double value1 = 1023; double value2 = 1534; double value3 = 2342; // Call the Add service operation. double result = client.Add(value1, value2); Console.WriteLine("Adding({0}, {1}) = {2}", value1, value2, result); // Call the Subtract service operation. result = client.Subtract(value3, value2); Console.WriteLine("Subtracting ({0}, {1}) = {2}", value3, value2, result); // Closing the client gracefully closes the connection and cleans up resources client.Close(); } catch (EndpointNotFoundException) { Console.WriteLine("Unable to connect to the calculator service because a valid endpoint was not found."); } Console.WriteLine("Press <ENTER> to exit."); Console.ReadLine(); }
public static void Main(string[] args) { /* * ListCounters("ServiceModelEndpoint 4.0.0.0"); * ListCounters("ServiceModelOperation 4.0.0.0"); * ListCounters("ServiceModelService 4.0.0.0"); */ Console.WriteLine("Press <ENTER> to start client."); Console.WriteLine(); Console.ReadLine(); CalculatorServiceClient client = new CalculatorServiceClient(); double value1 = 100.0; double value2 = 15.99; double result = client.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); value1 = 145.0; value2 = 76.54; result = client.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); value1 = 9.0; value2 = 81.25; result = client.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); value1 = 22.0; value2 = 7.0; result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); PerformanceCounter counter = new PerformanceCounter("Test category", "Test counter"); Random random = new Random(); bool running = true; while (running) { value1 = random.NextDouble() * 100.0; value2 = random.NextDouble() * 100.0; Parallel.Invoke( () => client.Add(value1, value2), () => client.Add(value1, value2), () => client.Add(value1, value2) ); Console.WriteLine("Test: {0}", counter.NextValue()); } client.Close(); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client."); Console.ReadLine(); }
public static void Main() { try { DynamicEndpoint dynamicEndpoint = new DynamicEndpoint(ContractDescription.GetContract(typeof(ICalculatorService)), new NetTcpBinding()); Uri redmondScope = new Uri("net.tcp://Microsoft.Samples.Discovery/RedmondLocation"); Uri seattleScope = new Uri("net.tcp://Microsoft.Samples.Discovery/SeattleLocation"); Uri portlandScope = new Uri("net.tcp://Microsoft.Samples.Discovery/PortlandLocation"); dynamicEndpoint.FindCriteria.Scopes.Add(redmondScope); dynamicEndpoint.FindCriteria.Scopes.Add(seattleScope); dynamicEndpoint.FindCriteria.Scopes.Add(portlandScope); // Specify the custom ScopeMatchBy dynamicEndpoint.FindCriteria.ScopeMatchBy = new Uri("net.tcp://Microsoft.Samples.Discovery/ORExactMatch"); CalculatorServiceClient client = new CalculatorServiceClient(dynamicEndpoint); Console.WriteLine("Discovering CalculatorService."); Console.WriteLine("Looking for a Calculator Service that matches either of the scopes:"); Console.WriteLine(" " + redmondScope); Console.WriteLine(" " + seattleScope); Console.WriteLine(" " + portlandScope); Console.WriteLine(); double value1 = 1023; double value2 = 1534; double value3 = 2342; // Call the Add service operation. double result = client.Add(value1, value2); Console.WriteLine("Adding({0}, {1}) = {2}", value1, value2, result); // Call the Subtract service operation. result = client.Subtract(value3, value2); Console.WriteLine("Subtracting ({0}, {1}) = {2}", value3, value2, result); //Closing the client gracefully closes the connection and cleans up resources client.Close(); } catch (EndpointNotFoundException) { Console.WriteLine("Unable to connect to the calculator service because a valid endpoint was not found."); } Console.WriteLine("Press <ENTER> to exit."); Console.ReadLine(); }
static void InvokeCalculatorService(EndpointAddress endpointAddress) { // Create a client CalculatorServiceClient client = new CalculatorServiceClient(new WSHttpBinding(), endpointAddress); Console.WriteLine("Invoking CalculatorService at {0}", endpointAddress); double value1 = 100.00D; double value2 = 15.99D; // Call the Add service operation. double result = client.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); //Closing the client gracefully closes the connection and cleans up resources client.Close(); }
static void Main(string[] args) { InstanceContext instanceContext = new InstanceContext(new CallBackHandler()); CalculatorServiceClient client = new CalculatorServiceClient(instanceContext); client.AddTo(5D); client.SubstractFrom(3D); client.MultiplyBy(12D); client.DivideBy(2D); client.Clear(); Console.ReadLine(); client.Close(); Console.WriteLine("Terminado"); Console.ReadKey(); }
public static void Main(string[] args) { EchoServiceClient echoClient = new EchoServiceClient(); Console.WriteLine("Echo(\"Is anyone there?\") returned: " + echoClient.Echo("Is anyone there?")); echoClient.Close(); CalculatorServiceClient calculatorClient = new CalculatorServiceClient(); Console.WriteLine("Add(5) returned: " + calculatorClient.Add(5)); Console.WriteLine("Add(-3) returned: " + calculatorClient.Add(-3)); calculatorClient.Close(); Console.WriteLine(); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); }
static void Main(string[] args) { // Create a client. CalculatorServiceClient client = new CalculatorServiceClient(); // Perform addition using a typed message. MyMessage request = new MyMessage(); request.N1 = 100D; request.N2 = 15.99D; request.Operation = "+"; MyMessage response = ((ICalculatorService)client).Calculate(request); Console.WriteLine("Add({0},{1}) = {2}", request.N1, request.N2, response.Result); //Closing the client releases all communication resources. client.Close(); Console.ReadLine(); }
static void Main(string[] args) { var ServiceHost = new ServiceHost(typeof(CalculatorService)); ServiceHost.Open(); var Client = new CalculatorServiceClient(); try { //Client.Divide(1, 0); var Result = Client.WeighPickle(new Pickle { Name = "Bob", Bumps = 12 }); Console.WriteLine(Result); Client.Close(); } catch (Exception) { Client.Abort(); throw; } Console.ReadLine(); }
private void BtnLogin_Click(object sender, EventArgs e) { CalculatorServiceClient client = new CalculatorServiceClient("Username"); try { client.ClientCredentials.UserName.UserName = txtUsername.Text; client.ClientCredentials.UserName.Password = txtPassword.Text; client.Open(); client.Login(); Form form = new Calculator(txtUsername.Text, txtPassword.Text); this.Hide(); form.Show(); client.Close(); } catch (Exception exception) { MessageBox.Show(exception.InnerException.Message); client.Abort(); } }
static void InvokeCalculatorService(EndpointAddress endpointAddress, Uri viaUri) { // Create a client CalculatorServiceClient client = new CalculatorServiceClient(new NetTcpBinding(), endpointAddress); Console.WriteLine("Invoking CalculatorService at {0}", endpointAddress.Uri); // if viaUri is not null then add the approprate ClientViaBehavior. if (viaUri != null) { client.Endpoint.Behaviors.Add(new ClientViaBehavior(viaUri)); Console.WriteLine("Using the viaUri {0}", viaUri); } Console.WriteLine(); double value1 = 100.00D; double value2 = 15.99D; // Call the Add service operation. double result = client.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation. result = client.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation. result = client.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation. result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); Console.WriteLine(); // Closing the client gracefully closes the connection and cleans up resources client.Close(); }
private void CalculateResults() { CalculatorServiceClient proxy = null; try { double value1 = Convert.ToDouble(textValue1.Text); double value2 = Convert.ToDouble(textValue2.Text); string endpointName; if (ComboBoxServiceConnection.SelectedIndex == 0) endpointName = "CalculatorService"; else { endpointName = "RouterService"; } proxy = new CalculatorServiceClient(endpointName); using (OperationContextScope scope = new OperationContextScope(proxy.InnerChannel)) { AddOptionalRoundingHeader(proxy); labelAddResult.Text = proxy.Add(value1, value2).ToString(); labelSubResult.Text = proxy.Subtract(value1, value2).ToString(); labelMultResult.Text = proxy.Multiply(value1, value2).ToString(); if (value2 != 0.00) labelDivResult.Text = proxy.Divide(value1, value2).ToString(); else labelDivResult.Text = "Divide by 0"; proxy.Close(); } } catch (FormatException) { MessageBox.Show("Invalid numeric value, cannot calculate", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (TimeoutException) { if (proxy != null) proxy.Abort(); MessageBox.Show("Timeout - cannot connect to service", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (CommunicationException) { if (proxy != null) proxy.Abort(); MessageBox.Show("Unable to communicate with the service", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { if (proxy != null) proxy.Close(); } }
static void InvokeCalculatorService(EndpointAddress endpointAddress) { // Create a client CalculatorServiceClient client = new CalculatorServiceClient(); // Connect to the discovered service endpoint client.Endpoint.Address = endpointAddress; Console.WriteLine("Invoking CalculatorService at {0}", endpointAddress); double value1 = 100.00D; double value2 = 15.99D; // Call the Add service operation. double result = client.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation. result = client.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation. result = client.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation. result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); Console.WriteLine(); // Close the client to close the connection and clean up resources client.Close(); }