static void Main(string[] args) { //ListAllBindingElements(new WSHttpBinding()); //GetBindingDefaultValue(new WSHttpBinding()); //IClientChannel string uri = "http://127.0.0.1:9000/calculatorservice"; ServiceHost host = new ServiceHost(typeof(Calculator), new Uri(uri)); host.AddServiceEndpoint(typeof(ICalculator), new SimpleBinding(), ""); if (host.Description.Behaviors.Find <ServiceMetadataBehavior>() == null) { ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; behavior.HttpGetUrl = new Uri("http://127.0.0.1:9000/calculatorservice/metadata"); host.Description.Behaviors.Add(behavior); } try { host.Open(); ChannelFactory <ICalculatorChannel> factory = new ChannelFactory <ICalculatorChannel>(new SimpleBinding(), uri); ICalculatorChannel proxy = factory.CreateChannel(); Console.WriteLine(proxy.Add(2, 3)); proxy.Close();// from IClientChannel Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex); } }
public static void Main() { ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = "Test.config"; Configuration newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); ConfigurationChannelFactory <ICalculatorChannel> factory1 = new ConfigurationChannelFactory <ICalculatorChannel>("endpoint1", newConfiguration, new EndpointAddress("http://localhost:8000/servicemodelsamples/service")); ICalculatorChannel client1 = factory1.CreateChannel(); ConfigurationChannelFactory <ICalculatorChannel> factory2 = new ConfigurationChannelFactory <ICalculatorChannel>("endpoint2", newConfiguration, new EndpointAddress("net.tcp://localhost:8080/servicemodelsamples/service")); ICalculatorChannel client2 = factory2.CreateChannel(); // Call the Add service operation. double value1 = 100.00D; double value2 = 15.99D; double result = client1.Add(value1, value2); Console.WriteLine("(HTTP)Add({0},{1}) = {2}", value1, value2, result); result = client2.Add(value1, value2); Console.WriteLine("(TCP) Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation. value1 = 145.00D; value2 = 76.54D; result = client1.Subtract(value1, value2); Console.WriteLine("(HTTP)Subtract({0},{1}) = {2}", value1, value2, result); result = client2.Subtract(value1, value2); Console.WriteLine("(TCP) Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation. value1 = 9.00D; value2 = 81.25D; result = client1.Multiply(value1, value2); Console.WriteLine("(HTTP)Multiply({0},{1}) = {2}", value1, value2, result); result = client2.Multiply(value1, value2); Console.WriteLine("(TCP) Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation. value1 = 22.00D; value2 = 7.00D; result = client1.Divide(value1, value2); Console.WriteLine("(HTTP)Divide({0},{1}) = {2}", value1, value2, result); result = client2.Divide(value1, value2); Console.WriteLine("(TCP) Divide({0},{1}) = {2}", value1, value2, result); // Closing the connection gracefully and cleaning up resources client1.Close(); client2.Close(); Console.WriteLine("Press <ENTER> to exit."); Console.ReadLine(); }
public CalculatorRepo(string endpointAddress, double timeout) { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); binding.SendTimeout = TimeSpan.FromSeconds(timeout); binding.MaxBufferSize = int.MaxValue; binding.MaxReceivedMessageSize = int.MaxValue; binding.AllowCookies = true; binding.ReaderQuotas = XmlDictionaryReaderQuotas.Max; EndpointAddress address = new EndpointAddress(endpointAddress); ChannelFactory <ICalculatorChannel> factory = new ChannelFactory <ICalculatorChannel>(binding, address); this.proxy = factory.CreateChannel(); }
static void Main() { Console.WriteLine("Press <ENTER> to terminate client once the output is displayed."); Console.WriteLine(); // Create a client //<snippet3> ChannelFactory <ICalculatorChannel> factory = new ChannelFactory <ICalculatorChannel>(); ICalculatorChannel channelClient = factory.CreateChannel(); // BeginAdd double value1 = 100.00D; double value2 = 15.99D; IAsyncResult arAdd = channelClient.BeginAdd(value1, value2, AddCallback, channelClient); Console.WriteLine("Add({0},{1})", value1, value2); //</snippet3> // BeginSubstract value1 = 145.00D; value2 = 76.54D; IAsyncResult arSubtract = channelClient.BeginSubtract(value1, value2, SubtractCallback, channelClient); Console.WriteLine("Subtract({0},{1})", value1, value2); // Multiply value1 = 9.00D; value2 = 81.25D; double result = channelClient.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Divide value1 = 22.00D; value2 = 7.00D; result = channelClient.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); Console.ReadLine(); //Closing the client gracefully closes the connection and cleans up resources channelClient.Close(); }
public async Task <int> AddAsync(int intA, int intB) { BasicHttpBinding binding = new BasicHttpBinding { SendTimeout = TimeSpan.FromSeconds(10000), MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, AllowCookies = true, ReaderQuotas = XmlDictionaryReaderQuotas.Max }; binding.Security.Mode = BasicHttpSecurityMode.None; EndpointAddress address = new EndpointAddress("http://www.dneonline.com/calculator.asmx"); ChannelFactory <ICalculatorChannel> factory = new ChannelFactory <ICalculatorChannel>(binding, address); this.proxy = factory.CreateChannel(); return(await this.proxy.AddAsync(intA, intB)); }