private async void CalcSum() { var service = new CalculatorServiceReference.CalculatorServiceClient(); int sum = await service.SumAsync(A, B); Sum = sum; }
/// <summary> /// wcf 服务引用的调用 /// </summary> /// <returns></returns> public JsonResult GetDataByWcf() { CalculatorServiceReference.CalculatorServiceClient srv = new CalculatorServiceReference.CalculatorServiceClient(); var res = srv.Add(2.34, 4.32); var res1 = srv.QueryBook(1); return(Json(res)); }
public ActionResult Calculate(FormCollection collection, string Sum, string Subtract) { CalculatorServiceReference.CalculatorServiceClient Client = new CalculatorServiceReference.CalculatorServiceClient("BasicHttpBinding_ICalculatorService"); if (!string.IsNullOrEmpty(Sum)) { ViewBag.Message = Client.sum(Convert.ToInt32(collection["Number1"]), Convert.ToInt32(collection["Number2"])); } if (!string.IsNullOrEmpty(Subtract)) { ViewBag.Message = Client.Subtract(Convert.ToInt32(collection["Number1"]), Convert.ToInt32(collection["Number2"])); } return(View("Index")); }
public ActionResult SubmitOperation(InputModel obj, string Addition, string Substraction) { CalculatorServiceReference.CalculatorServiceClient clien = new CalculatorServiceReference.CalculatorServiceClient(); if (!String.IsNullOrEmpty(Addition)) { obj.result = clien.add(obj.value1, obj.value2); } if (!String.IsNullOrEmpty(Substraction)) { obj.result = clien.substract(obj.value1, obj.value2); } return(View("Index", obj)); }
private void CalculateResults() { CalculatorServiceClient proxy = null; try { double value1 = Convert.ToDouble(textValue1.Text); double value2 = Convert.ToDouble(textValue2.Text); Debug.WriteLine("Calculating values"); string endpointName; if (ComboBoxServiceConnection.SelectedIndex == 0) endpointName = "CalculatorService"; else endpointName = "RouterService"; proxy = new CalculatorServiceReference.CalculatorServiceClient(endpointName); 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"; } 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(); } }