private void UnsecuredTcp() { //<snippet2> // Create an instance of the NetTcpBinding and set the // security mode to none. NetTcpBinding myBinding = new NetTcpBinding(); myBinding.Security.Mode = SecurityMode.None; // Create the address string, or get it from configuration. string tcpUri = "net.tcp://machineName:8008/Calculator"; // Create an endpoint address with the address. EndpointAddress myEndpointAddress = new EndpointAddress(tcpUri); // Create an instance of the WCF client. The client // code was generated using the Svcutil.exe tool. CalculatorClient cc = new CalculatorClient(myBinding, myEndpointAddress); try { cc.Open(); //</snippet2> // Begin using the calculator. Console.WriteLine(cc.Divide(100, 2)); // Close the client. cc.Close(); } catch (TimeoutException tex) { Console.WriteLine(tex.Message); cc.Abort(); } catch (CommunicationException cex) { Console.WriteLine(cex.Message); cc.Abort(); } finally { Console.WriteLine("Closed the client"); Console.ReadLine(); } }
private void UnsecuredHttp() { //<snippet1> // Create an instance of the BasicHttpBinding. // By default, there is no security. BasicHttpBinding myBinding = new BasicHttpBinding(); // Create the address string, or get it from configuration. string httpUri = "http://localhost/Calculator"; // Create an endpoint address with the address. EndpointAddress myEndpoint = new EndpointAddress(httpUri); // Create an instance of the WCF client. The client // code was generated using the Svcutil.exe tool. CalculatorClient cc = new CalculatorClient(myBinding, myEndpoint); try { cc.Open(); // Begin using the calculator. Console.WriteLine(cc.Divide(100, 2)); // Close the client. cc.Close(); } catch (TimeoutException tex) { Console.WriteLine(tex.Message); cc.Abort(); } catch (CommunicationException cex) { Console.WriteLine(cex.Message); cc.Abort(); } finally { Console.WriteLine("Closed the client"); Console.ReadLine(); } //</snippet1> }