Esempio n. 1
0
        private static async void Execute()
        {
            var client = new InvoiceServiceClient("NetTcp_IInvoiceService");

            try
            {
                var invoice = new Invoice
                {
                    CustomerId  = "fault" + Guid.NewGuid().ToString(),
                    InvoiceDate = DateTime.Now.AddHours(-1)
                };

                var invoice2 = new Invoice
                {
                    CustomerId  = Guid.NewGuid().ToString(),
                    InvoiceDate = DateTime.Now
                };

                await client.SubmitInvoiceAsync(invoice);

                await client.SubmitInvoiceAsync(invoice2);

                var response = await client.GetInvoicesAsync();

                foreach (var inv in response)
                {
                    Console.WriteLine(inv.CustomerId);
                }

                client.Close();
            }
            catch (FaultException fe)
            {
                Console.WriteLine($"FaultException: {fe.GetType()}");
                client.Abort();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine($"FaultException: {ce.GetType()}");
                client.Abort();
            }
            catch (TimeoutException te)
            {
                Console.WriteLine($"FaultException: {te.GetType()}");
                client.Abort();
            }
        }
Esempio n. 2
0
        private static async void Execute()
        {
            var hwClient      = new HelloWorldClient("NetTcpBinding_IHelloWorld");
            var invoiceClient = new InvoiceServiceClient("BasicHttpBinding_IInvoiceService");

            var person = new Person
            {
                FirstName = "Lucas",
                LastName  = "Amorim"
            };

            var responseHello = await hwClient.SayHelloAsync(person);

            Console.WriteLine(responseHello);

            var responseBye = await hwClient.SayByeAsync(person);

            Console.WriteLine(responseBye);

            var invoice = new Invoice
            {
                CustomerId  = "cus_AAA",
                InvoiceDate = DateTime.Now
            };

            await invoiceClient.SubmitInvocieAsync(invoice);

            Console.WriteLine("Invoice submmitted");

            var responseGetInvoices = await invoiceClient.GetInvoicesAsync();

            foreach (var item in responseGetInvoices)
            {
                Console.WriteLine(item.CustomerId + " " + item.InvoiceDate + " " + item.ExtensionData);
            }
        }