Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
0
    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();
         }
    }
Пример #4
0
        static void Main(string[] args)
        {
            EchoClient client = new EchoClient();

            Console.Write("\nSending Echo request to service...");

            string result = client.Echo("Hello, DataCore!");

            Console.WriteLine("done");

            Console.WriteLine("Echo(\"Hello, DataCore!\") = {0}", result);

            Console.WriteLine("\nPress <Enter> to terminate the client.");
            Console.ReadLine();
            client.Close();
        }