static void Main(string[] args) { PermissionCertificatePolicy.Enact("CN=HTTPS-Server"); using (ServiceReference1.CalculatorClient service = new ServiceReference1.CalculatorClient("BasicHttpBinding_ICalculator")) { service.ClientCredentials.UserName.UserName = "******"; service.ClientCredentials.UserName.Password = "******"; Console.WriteLine("调用 WCF 服务 ( {0} ) 开始!", "BasicHttpBinding_ICalculator"); Console.WriteLine("service.Add(1, 2) = {0}", service.Add(1, 2)); Console.WriteLine("service.Sub(2, 3) = {0}", service.Sub(2, 3)); Console.WriteLine("service.Mul(3, 4) = {0}", service.Mul(3, 4)); ServiceReference1.DivResult divResult = service.Div(5, 2); Console.WriteLine("service.Div(5, 2) = {0} 余 {1} ", divResult.DivData, divResult.ModData); Console.WriteLine("调用 WCF 服务 ( {0} ) 结束!", "BasicHttpBinding_ICalculator"); Console.WriteLine(); } Console.WriteLine("按回车键结束!"); Console.ReadLine(); }
public static void CallFromWCF() { ServiceReference1.CalculatorClient client = new ServiceReference1.CalculatorClient(); client.ClientCredentials.UserName.UserName = "******"; client.ClientCredentials.UserName.Password = "******"; client.Endpoint.Behaviors.Add(new InspectorBehavior()); double result= client.Add(1,2); Console.WriteLine(result.ToString()); }
static void Main(string[] args) { Console.WriteLine("Press enter to call the service"); Console.ReadLine(); var proxy = new ServiceReference1.CalculatorClient("BasicHttpEndpoint"); proxy.ClientCredentials.UserName.UserName = "******"; proxy.ClientCredentials.UserName.Password = "******"; var arguments = new ServiceReference1.Arguments(); arguments.Arg1 = 1; arguments.Arg2 = 2; var result = proxy.Add(arguments); Console.WriteLine("Result: "+ result.Value); Console.WriteLine("Press enter to close the application :)"); Console.ReadLine(); }
static void Main() { // Create a client ServiceReference1.CalculatorClient client = new ServiceReference1.CalculatorClient(); // Call the Add service operation double value1 = 100.00D; double value2 = 15.99D; double result = client.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation value1 = 145.00D; value2 = 76.54D; result = client.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation value1 = 9.00D; value2 = 81.25D; result = client.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation value1 = 22.00D; value2 = 7.00D; result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); //Closing the client gracefully closes the connection and cleans up resources client.Close(); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client."); Console.ReadLine(); }
private void AddButton_Click(object sender, EventArgs e) { Result.Text = Math.Add(Convert.ToDouble(FirstNumber.Text), Convert.ToDouble(SecondNumber.Text)).ToString(); }