static void TestEcho() { InstanceContext ctx = new InstanceContext(new CalculatorCallBack()); EchoClient echo = new EchoClient(ctx); var result = echo.Echo("welcome to wcf!"); Console.WriteLine(result); }
static void TestOneWay() { // NOTE it's really good to test the IsOneWay functionality, it works, as expected! InstanceContext ctx = new InstanceContext(new CalculatorCallBack()); EchoClient echo = new EchoClient(ctx); Console.WriteLine("start to call SayHello...{0}", DateTime.Now); echo.SayHello("scotty"); Console.WriteLine("end of calling SayHello...{0}", DateTime.Now); }
public static void Main(String[] args) { EchoClient conversant=null; StreamWriter swriter=null; StreamReader sreader=null; try { //Host name comes from command line //If no host specified, local machine is host String host=args.Length==1?args[0]:"127.0.0.1"; //Connect to Echo server conversant=new EchoClient(host); //Get the stream between server and client NetworkStream ns=conversant.GetStream(); //Create a user-friendly StreamWriter swriter=new StreamWriter(ns); //Create a user-friendly StreamReader sreader=new StreamReader(ns); //Prompt user for message to send to server //Period "exit" tells server to end session String input; Console.Write("Enter screen name: "); while ((input=Console.ReadLine())!="exit") { //Send message to server swriter.WriteLine(input); swriter.Flush(); //Get the Echo from the server String returndata=sreader.ReadLine(); Console.WriteLine("Reply from "+host+": "+returndata); Console.Write("Enter text: \"exit\" to stop: "); } //Send final message and scram swriter.WriteLine("."); swriter.Flush(); } catch (Exception e) { Console.WriteLine(e+" "+e.StackTrace); } finally { //Close the connection whether exception thrown or not if (swriter!=null) swriter.Close(); if (sreader!=null) sreader.Close(); if (conversant!=null) conversant.Close(); } }
static void Main(string[] args) { Trace.Listeners.Add(new ConsoleTraceListener()); using (EchoClient client = new EchoClient()) { client.Port = 8088; client.Host = "localhost"; client.Start(); Console.WriteLine("Press enter key to exit..."); Console.ReadLine(); client.Stop(); } }
static void Main() { // Note that the ListenUri must be communicated out-of-band. // That is, the metadata exposed by the service does not publish // the ListenUri, and thus the svcutil-generated config doesn't // know about it. // On the client, use ClientViaBehavior to specify // the Uri where the server is listening. Uri via = new Uri("http://localhost/ServiceModelSamples/service.svc"); // Create a client to talk to the Calculator contract CalculatorClient calcClient = new CalculatorClient(); calcClient.ChannelFactory.Endpoint.Behaviors.Add( new ClientViaBehavior(via)); double value1 = 100.00D; double value2 = 15.99D; double result = calcClient.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); calcClient.Close(); // Create a client to talk to the Echo contract that is located // at the same EndpointAddress and ListenUri as the calculator contract EchoClient echoClient = new EchoClient("WSHttpBinding_IEcho"); echoClient.ChannelFactory.Endpoint.Behaviors.Add( new ClientViaBehavior(via)); Console.WriteLine(echoClient.Echo("Hello!")); echoClient.Close(); // Create a client to talk to the Echo contract that is located // at a different EndpointAddress, but the same ListenUri EchoClient echoClient1 = new EchoClient("WSHttpBinding_IEcho1"); echoClient1.ChannelFactory.Endpoint.Behaviors.Add( new ClientViaBehavior(via)); Console.WriteLine(echoClient1.Echo("Hello!")); echoClient.Close(); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client application."); Console.ReadLine(); }
public static void Main(String[] args) { EchoClient client = null; try { handler += new EventHandler(Handler); SetConsoleCtrlHandler(handler, true); //Host name comes from command line //If no host specified, local machine is host String host = args.Length == 1 ? args[0] : "127.0.0.1"; //creates connection client = new EchoClient(host); //gets stream between server and client NetworkStream ns = client.GetStream(); //creates writer and reader swriter = new StreamWriter(ns); sreader = new StreamReader(ns); //tells the user how to exit the chat properly Console.Write("Enter text: \"exit\" to leave the chat: \n"); //prompts the user the screen name for this client String input; Console.Write("Enter screen name: "); //starts thread to read messages being sent from other clients //from the server Thread readthread = new Thread(new ThreadStart(client.Reader)); readthread.Start(); while ((input = Console.ReadLine()) != "exit") { //sends the message to the sever to be sent to //other clients swriter.WriteLine(input); swriter.Flush(); } //tells the server that the client has left swriter.WriteLine("exit"); swriter.Flush(); //tell reader to stop reading endreader = true; //holds the console while it cleans up from exiting without typing "exit" while (!exitSystem) { Thread.Sleep(500); } } catch (Exception e) { Console.WriteLine(e + " " + e.StackTrace); } }
static void TestCallback() { InstanceContext ctx = new InstanceContext(new CalculatorCallBack()); EchoClient client = new EchoClient(ctx); client.SayHello("scotty & juicy"); }