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