Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // Vytvorenie instancie proxy triedy, pomocou ktorej mozeme volat vzdialene metody
            var client = new SimpleServiceClient();

            // Zavolame vzdialenu metodu GetData - sluzba vrati retazec
            var resultString = client.GetData(123);

            Console.WriteLine(resultString);

            var compositeType = new CompositeType {
                StringValue = "Volam WCF sluzbu", BoolValue = true
            };
            var resultCompositeType = client.GetDataUsingDataContract(compositeType);

            Console.WriteLine(resultCompositeType.StringValue);

            Console.ReadLine();

            client.Close();
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            var simpleServiceClient       = new SimpleServiceClient();
            var simpleServiceCustomClient = new SimpleServiceCustomProxy(new BasicHttpBinding(), new System.ServiceModel.EndpointAddress(@"http://localhost:8123/SimpleService/"));
            var dulplexServiceClient      = new DulplexServiceClient(new System.ServiceModel.InstanceContext(new DulplexServiceCallback()));
            var dulplexServiceClient2     = new DulplexServiceClient(new System.ServiceModel.InstanceContext(new DulplexServiceCallback()));

            try
            {
                Console.WriteLine("Client - Start.");
                Console.WriteLine(simpleServiceClient.GetData(5));
                Console.WriteLine(simpleServiceCustomClient.GetData(2));
                var obj = new Contracts.CompositeType();
                obj.BoolValue   = true;
                obj.StringValue = "hello";
                var obj1 = simpleServiceCustomClient.GetDataUsingDataContract(obj);
                var obj2 = simpleServiceClient.GetDataUsingDataContract(obj);
                simpleServiceClient.Close();

                dulplexServiceClient.Subscribe();
                dulplexServiceClient2.Subscribe();
                dulplexServiceClient2.Subscribe();
                dulplexServiceClient2.UnSubscribe();
                dulplexServiceClient2.UnSubscribe();
                dulplexServiceClient2.UnSubscribe();
                dulplexServiceClient2.Close();
                dulplexServiceClient.Add(7, 8);
                //dulplexServiceClient.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                simpleServiceClient.Abort();
                dulplexServiceClient.Abort();
            }
            Console.Read();
        }