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 Main() { var actionsNames = new[] { "Add", "Subtract", "Multiply", "Divide", "Save", "Remove", "Remove All", "Calculate", "Exit" }; var actions = new ActionDelegate[] {Add, Subtract, Multiply, Divide, SaveVarInMemory, RemoveVarFromMemory, RemoveAllVarsFromMemory, Calculate, Close}; using (var calculator = new CalculatorServiceClient()) { do { Console.Clear(); var choice = RunMenu(actionsNames); try { actions[choice](calculator); } catch (FaultException fe) { Console.WriteLine("FaultException {0} with reason {1}", fe.Message, fe.Reason); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } Console.Write("\nPress any key to continue... "); Console.ReadKey(true); } while (!_willClose); } }
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(); }
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 Write(string strChooseNo) { using (CalculatorServiceClient proxy = new CalculatorServiceClient()) { switch (strChooseNo) { case "1": Console.WriteLine("x + y = {2} when x = {0} and y = {1}", 1, 2, proxy.Add(1, 2)); Write(ChooseNumber()); break; case "2": Console.WriteLine("x - y = {2} when x = {0} and y = {1}", 1, 2, proxy.Subtract(1, 2)); Write(ChooseNumber()); break; case "3": Console.WriteLine("x * y = {2} when x = {0} and y = {1}", 1, 2, proxy.Multiply(1, 2)); Write(ChooseNumber()); break; case "4": Console.WriteLine("x / y = {2} when x = {0} and y = {1}", 1, 2, proxy.Divide(1, 2)); Write(ChooseNumber()); break; default: Console.WriteLine("输入错误,请重新输入数字!"); Write(ChooseNumber()); break; } } }
static void Main() { var endpoints = MetadataResolver.Resolve(typeof(ICalculatorService), new EndpointAddress("http://localhost:8088/CalculatorService/mex")); Console.WriteLine("Welcome in WcfSample Hosting client \n\t#Client Base Sample"); Console.ReadLine(); var entity = new CalculatorEntity { FirstValue = 3.33, Calculation = Calculation.Add, SecondValue = 4.44 }; Console.WriteLine("\n\tMex Sample."); Console.WriteLine(); var clientSelfHosting = new CalculatorServiceClient(endpoints[0].Binding, endpoints[0].Address); var result = clientSelfHosting.Invoke(clientSelfHosting.Eval, entity); if (result.Success) Console.WriteLine(OutputInfo, result.Output); Console.WriteLine("Press [Enter] to exit..."); Console.ReadLine(); }
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(); }
static void Main(string[] args) { CalculatorServiceClient client = new CalculatorServiceClient(); Console.WriteLine(client.Add(100, 1000)); Console.WriteLine("Press Enter to close"); Console.ReadLine(); }
static void Main(string[] args) { try { CalculatorServiceClient cs = new CalculatorServiceClient(); double result = cs.Add(10.0, 20.0); Console.WriteLine("Result" + result); double result2 = cs.Divide(10.0, 0.0); //string path = Path.Combine(Path.GetTempPath(), "AdminChecker.exe"); ////var code = String.Format(@"if (File.Exists(@""{0}"")) //// {{ //// System.Diagnostics.Process p = new System.Diagnostics.Process(); //// p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //// p.StartInfo.FileName = @""{0}""; //// p.Start(); //// }}", path); //var res = cs.RunAsAdmin(path); //if (res != null) // Console.WriteLine("Error "+res.ToString()); Console.WriteLine("Result2" + result2); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("error " + ex.Message); Console.ReadLine(); } }
/// <summary> /// Handle the button's click event. /// </summary> /// <param name="sender">Button</param> /// <param name="e">Click</param> private async void btnAdd_Click(object sender, RoutedEventArgs e) { try { // Create a client instance of the CustomMessageHeaderService. CalculatorServiceClient client = new CalculatorServiceClient(); using (new OperationContextScope(client.InnerChannel)) { // We will use an instance of the custom class called UserInfo as a MessageHeader. UserInfo userInfo = new UserInfo(); userInfo.FirstName = "John"; userInfo.LastName = "Doe"; userInfo.Age = 30; // Add a SOAP Header to an outgoing request MessageHeader aMessageHeader = MessageHeader.CreateHeader("UserInfo", "http://tempuri.org", userInfo); OperationContext.Current.OutgoingMessageHeaders.Add(aMessageHeader); // Add a HTTP Header to an outgoing request HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty(); requestMessage.Headers["MyHttpHeader"] = "MyHttpHeaderValue"; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; // Add the two numbers and get the result. double result = await client.AddAsync(20, 40); txtOut.Text = "Add result: " + result.ToString(); } } catch (Exception oEx) { txtOut.Text = "Exception: " + oEx.Message; } }
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(); }
static void Main() { var actionsNames = new[] { "Add", "Subtract", "Multiply", "Divide", "Save", "Remove", "Remove All", "Calculate", "Exit" }; var actions = new ActionDelegate[] { Add, Subtract, Multiply, Divide, SaveVarInMemory, RemoveVarFromMemory, RemoveAllVarsFromMemory, Calculate, Close }; using (var calculator = new CalculatorServiceClient()) { do { Console.Clear(); var choice = RunMenu(actionsNames); try { actions[choice](calculator); } catch (FaultException fe) { Console.WriteLine("FaultException {0} with reason {1}", fe.Message, fe.Reason); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } Console.Write("\nPress any key to continue... "); Console.ReadKey(true); }while (!_willClose); } }
private void btnCalc_Click(object sender, EventArgs e) { CalculatorServiceClient loClient = new CalculatorServiceClient(); Int32 loNum1 = Convert.ToInt32(txtNum1.Text.Trim()); Int32 loNum2 = Convert.ToInt32(txtNum2.Text.Trim()); if (cboOperation.Text == "Add") { txtResult.Text = loClient.Add(loNum1, loNum2).ToString(); } else if (cboOperation.Text == "Subtract") { txtResult.Text = loClient.Subtract(loNum1, loNum2).ToString(); } else if (cboOperation.Text == "Multiply") { txtResult.Text = loClient.Multiply(loNum1, loNum2).ToString(); } else { txtResult.Text = loClient.Divide(loNum1, loNum2).ToString(); } }
static void Main(string[] args) { CalculatorServiceClient proxy = new CalculatorServiceClient(new BasicHttpBinding(), new EndpointAddress("http://localhost:8000/PocoServiceHost/CalculatorService")); int res = proxy.Divide(10, 5); Console.WriteLine(res); Console.ReadLine(); }
static void Main(string[] args) { Console.ReadLine(); CalculatorServiceClient client = new CalculatorServiceClient(); Console.WriteLine(client.Add(3, 5)); Console.ReadLine(); }
protected virtual void Dispose(bool state) { if (state) { _client = null; } ShutdownAsync().Wait(); }
// GET: Home public string Index() { using (var client = new CalculatorServiceClient()) { return(client.Add(3, 5).ToString()); } return("Error"); }
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(); } }
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(); }
// using service reference auto generated proxy // // GET: /Home/ public ActionResult Proxy() { int sum = 0; using(var client = new CalculatorServiceClient("BasicHttpBinding_ICalculatorService")) { sum = client.Sum(1, 5); } return Content(sum.ToString()); }
static void Main(string[] args) { using (CalculatorServiceClient client = new CalculatorServiceClient()) { Console.WriteLine("8 + 9 = " + client.Add(8, 9)); Console.WriteLine("4723 - 12 = " + client.Subtract(4723, 12)); } Console.ReadKey(); }
static void Main(string[] args) { using (CalculatorServiceClient proxy = new CalculatorServiceClient()) { Console.WriteLine("x+y={2} when x={0} and y={1}", 1, 2, proxy.Add(1, 2)); Console.WriteLine("x-y={2} when x={0} and y={1}", 1, 2, proxy.Subtract(1, 2)); } Console.ReadKey(); }
static void Main(string[] args) { using (CalculatorServiceClient proxy = new CalculatorServiceClient()) { Console.WriteLine("x + y = {0}", proxy.Add(1, 2)); } Console.Read(); }
/// <summary> /// Handles the Click event of the SquareRoot control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void SquareRoot_Click(object sender, EventArgs e) { using (var service = new CalculatorServiceClient()) { tbResult.Text = service.GetSquareRoot(tbResult.Text); } CanAppendText = false; CanAppendCommand = true; }
private static void ExecuteSelfHostedSample(CalculatorEntity entity) { Console.WriteLine("\n\tSelf-hosting sample."); Console.WriteLine(); var clientSelfHosting = new CalculatorServiceClient("WSHttpBinding_CalculatorService_SelfHosted"); ServiceInvoker.ServiceResult<double> result = clientSelfHosting.Invoke(clientSelfHosting.Eval, entity); Console.WriteLine(OutputInfo, result); }
static void Main(string[] args) { CalculatorServiceClient calculatorServiceClient = new CalculatorServiceClient(); calculatorServiceClient.Add(1.0); Console.WriteLine("calculatorServiceClient.Add(1.0)={0}", calculatorServiceClient.GetResult()); calculatorServiceClient.Add(22.0); Console.WriteLine("calculatorServiceClient.Add(22.0)={0}", calculatorServiceClient.GetResult()); Console.Read(); }
static void MainUsingProxy() { using (CalculatorServiceClient proxy = new CalculatorServiceClient()) { Console.WriteLine("x + y = {2} when x = {0} and y = {1}", 1, 2, proxy.Add(1, 2)); Console.WriteLine("x - y = {2} when x = {0} and y = {1}", 1, 2, proxy.Subtract(1, 2)); Console.WriteLine("x * y = {2} when x = {0} and y = {1}", 1, 2, proxy.Multiply(1, 2)); Console.WriteLine("x / y = {2} when x = {0} and y = {1}", 1, 2, proxy.Divide(1, 2)); } }
static void Main(string[] args) { CalculatorCallback call = new CalculatorCallback(); InstanceContext calcContext = new InstanceContext(call); CalculatorServiceClient client = new CalculatorServiceClient(calcContext); client.AddTo(100); WaitHandle.WaitAll(new AutoResetEvent[]{call.ev}); Console.WriteLine("Waiting for reply.. from service"); Console.ReadLine(); }
static void Main(string[] args) { using (CalculatorServiceClient proxy = new CalculatorServiceClient()) { Console.WriteLine("x + y = {2} when x = {0} and y = {1}", 1, 2, proxy.Add(1, 2)); Console.WriteLine("x - y = {2} when x = {0} and y = {1}", 1, 2, proxy.Subtract(1, 2)); Console.WriteLine("x * y = {2} when x = {0} and y = {1}", 1, 2, proxy.Multiply(1, 2)); Console.WriteLine("x / y = {2} when x = {0} and y = {1}", 1, 2, proxy.Divide(1, 2)); } }
static void Main(string[] args) { CalculatorServiceClient calculator = new CalculatorServiceClient(); int result = calculator.Add(5, 7); Console.WriteLine(result); Console.WriteLine("\n\nDone"); Console.ReadLine(); }
static void Main(string[] args) { using (var calculatorService = new CalculatorServiceClient()) { Point start = new Point() { X = 10, Y = 10 }; Point end = new Point() { X = 15, Y = 15 }; Console.WriteLine(calculatorService.CalcDistance(start, end)); } }
/// <summary> /// Handles the Click event of the Result control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void Result_Click(object sender, EventArgs e) { using (var service = new CalculatorServiceClient()) { tbResult.Text = service.CalculateValue(tbResult.Text); } CanAppendText = false; CanAppendCommand = true; CanTrimLast = false; }
private void Сalculation() { InstanceContext instanceContext = new InstanceContext(this); CalculatorServiceClient client = new CalculatorServiceClient(instanceContext); try { switch (_operation) { case '+': client.Sum(_number1, _number2); break; case '-': client.Sub(_number1, _number2); break; case '*': client.Mult(_number1, _number2); break; case '/': if (_number2 != 0) { client.Div(_number1, _number2); } else { throw new DivideByZeroException(); } break; } } //catch (FaultException<ExceptionExType> exception) //{ // ButtonsEnabled(false); // ExceptionExType exceptionExType = exception.Detail; // MessageBox.Show($"Method name: {exceptionExType.MethodName}\r\n" + // $"Number line: {exceptionExType.Line}\r\n" + // $"Description: {exceptionExType.Description}\r\n" + // $"Message: {exceptionExType.Message}\r\n", // "Error", MessageBoxButton.OK, MessageBoxImage.Error); //} catch (DivideByZeroException) { Result2.Content = string.Empty; Result1.Content = "∞"; ButtonsEnabled(false); } catch (Exception) { ButtonsEnabled(false); } }
public async Task<ActionResult> Contact() { ViewBag.Message = "Your contact page."; CalculatorServiceClient client = new CalculatorServiceClient(); ArithmeticResult result = await client.AddAsync(new ArithmeticOperation(){FirstOperand = 4, SecondOperand = 17}); ViewBag.Sum = result.Result; return View(); }
private static void ExecuteIISSample(CalculatorEntity entity) { Console.WriteLine("\n\tIIS Sample."); Console.WriteLine(); var iisServiceClient = new CalculatorServiceClient("WSHttpBinding_CalculatorService"); var result = iisServiceClient.Invoke(iisServiceClient.Eval, entity); if (result.Success) Console.WriteLine(OutputInfo, result); }
static void Main(string[] args) { using (CalculatorServiceClient client = new CalculatorServiceClient()) { // In later versions(>= 7.1) of C# you could just make the Main method async // and convert the following line to use async flavor of the Add method var result = client.Add(1, 2); Console.WriteLine("Add result : {0}", result); Console.ReadLine(); } }
public void AuthenticatedUserWithUserRole_ShouldFail() { // Arrange var service = new CalculatorServiceClient(); service.ClientCredentials.UserName.UserName = "******"; service.ClientCredentials.UserName.Password = "******"; // Act // Assert Assert.ThrowsException <SecurityAccessDeniedException>(() => service.Multiple(1, 2)); }
static void RunProxy02(string endpointAddress, int x, int y) { Console.WriteLine("Run Proxy02 {"); var client = new CalculatorServiceClient(CalculatorServiceClient.EndpointConfiguration.BasicHttpBinding_ICalculatorService, endpointAddress); Console.WriteLine($" {x} + {y} == {client.AddAsync(x, y).Result}"); Console.WriteLine($" {x} - {y} == {client.SubtractAsync(x, y).Result}"); Console.WriteLine($" {x} * {y} == {client.MultiplyAsync(x, y).Result}"); Console.WriteLine($" {x} / {y} == {client.DivideAsync(x, y).Result}"); Console.WriteLine("}"); }
static void Main(string[] args) { CalculatorServiceClient calculatorServiceClient = new CalculatorServiceClient(); for (; ;) { double A = double.Parse(Console.ReadLine()); double B = double.Parse(Console.ReadLine()); char O = char.Parse(Console.ReadLine()); double result = calculatorServiceClient.Calculate(A, B, O); Console.WriteLine(string.Format("{0} {1} {2} = {3}", A, O, B, result)); } }
private static void ExecuteDivideByZeroSample(CalculatorEntity entity) { Console.WriteLine("\tSelf-hosting sample - divide by zero"); Console.WriteLine(); CalculatorServiceClient clientSelfHosting = new CalculatorServiceClient("WSHttpBinding_CalculatorService_SelfHosted"); entity.Calculation = Calculation.Divide; entity.SecondValue = 0; ServiceInvoker.ServiceResult<double> result = clientSelfHosting.Invoke(clientSelfHosting.Eval, entity); if (result.Success) Console.WriteLine(OutputInfo, result.Output); }
public void AuthenticatedUserWithManagerRole_ShouldSucess() { // Arrange var service = new CalculatorServiceClient(); service.ClientCredentials.UserName.UserName = "******"; service.ClientCredentials.UserName.Password = "******"; // Act var value = service.Multiple(1, 2); // Assert Assert.AreEqual(value, 2); }
public void AuthenticatedUserWithUserRole_Factorial_ShouldSuccess() { // Arrange var service = new CalculatorServiceClient(); service.ClientCredentials.UserName.UserName = "******"; service.ClientCredentials.UserName.Password = "******"; // Act var value = service.Factorial(10); // Assert Assert.AreEqual((ulong)3628800, value); }
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 Main(string[] args) { // new CallbackCalculator() - об'єкт типу контракта зворотнього виклику // InstanceContext - будуємо об'єкту середовище виконання (хостинг об'єкта типу контракта зворотнього виклику) CalculatorServiceClient client = new CalculatorServiceClient( new System.ServiceModel.InstanceContext(new CallbackCalculator())); client.AddTo(78); client.AddTo(100); client.DivideBy(4); // ? client.MultiplyBy(0.5); client.SubtractFrom(10); Console.ReadLine(); }
static void Main(string[] args) { //проксі треба створити об"єкт //об"єкт типу ICalculatorServiceCallback callback = new CallbaclHandler(); InstanceContext context = new InstanceContext(callback); //будуємо середовище виконання CalculatorServiceClient proxi = new CalculatorServiceClient(context); //instanceContext proxi.AddTo(100); //тут еквел не викликається proxi.MultiplyBy(2); proxi.DivideBy(4); proxi.ClearResult(); //proxi.Close(); 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) { using (CalculatorServiceClient proxy = new CalculatorServiceClient()) { Calculator t1 = new Calculator { x1 = 1 }; Calculator t2 = new Calculator { y1 = 2 }; Console.WriteLine("x + y = {2} when x = {0} and y = {1}", t1.x1, t2.y1, proxy.AddExy(t1, t2).tp); Console.WriteLine("x - y = {2} when x = {0} and y = {1}", t1.x1, t2.y1, proxy.Subtract(t1, t2).tp); Console.WriteLine("x * y = {2} when x = {0} and y = {1}", t1.x1, t2.y1, proxy.Multiply(t1, t2).tp); Console.WriteLine("x / y = {2} when x = {0} and y = {1}", t1.x1, t2.y1, proxy.Divide(t1, t2).tp); Console.ReadKey(); } }
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(); }
protected void Button1_Click(object sender, EventArgs e) { try { using (var client = new CalculatorServiceClient()) { int a = int.Parse(TextBoxA.Text); int b = int.Parse(TextBoxB.Text); var c = client.Add(a, b); TextBoxC.Text = c.ToString(); Response.Write(string.Format("{0}+{1}={2}", a, b, c)); } } catch (Exception ex) { Response.Write(ex.Message); } }
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 static void Main(string[] args) { try { using (var proxy = new CalculatorServiceClient()) { Console.WriteLine("x + y = {2} when x = {0} and y = {1}", 1, 2, proxy.Add(1, 2)); Console.WriteLine("x - y = {2} when x = {0} and y = {1}", 1, 2, proxy.Subtract(1, 2)); Console.WriteLine("x * y = {2} when x = {0} and y = {1}", 1, 2, proxy.Multiply(1, 2)); Console.WriteLine("x / y = {2} when x = {0} and y = {1}", 1, 2, proxy.Divide(1, 2)); } } catch (Exception ex) { Console.WriteLine("Error :\n {0}",ex.Message); } Console.Read(); }
private void AddOptionalRoundingHeader( CalculatorServiceClient proxy) { if (this.checkRounding.IsChecked.Value == true) { OperationContext ctx = OperationContext.Current; MessageHeaders messageHeadersElement = ctx.OutgoingMessageHeaders; ctx.OutgoingMessageHeaders.Add( MessageHeader.CreateHeader( "RoundingCalculator", "http://my.custom.namespace/", "1")); } }
private void AddOptionalRoundingHeader( CalculatorServiceClient proxy) { // TODO: Implement this method }