Exemple #1
0
        private async void btnEnviar_Click(object sender, EventArgs e)
        {
            //using (NotasServiceClient client = new NotasServiceClient("WSHttpBinding_INotasService"))
            //{
            //    var nota = new Nota()
            //    {
            //        AlunoId = (int)cboAluno.SelectedValue,
            //        DisciplinaId = (int)cboDisciplina.SelectedValue,
            //        Pontos = Convert.ToDecimal(txtNota.Text)
            //    };

            //    await client.EnviarNotasAsync(nota);

            //    client.Close();
            //}

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                using (NotasServiceClient client = new NotasServiceClient("WSHttpBinding_INotasService"))
                {
                    try
                    {
                        var nota = new EscolaService.Nota()
                        {
                            AlunoId      = (int)cboAluno.SelectedValue,
                            DisciplinaId = (int)cboDisciplina.SelectedValue,
                            Pontos       = Convert.ToDecimal(txtNota.Text)
                        };

                        await client.EnviarNotasAsync(nota);

                        ts.Complete();
                    }
                    catch (FaultException <ErroProcessamento> ex)
                    {
                        MessageBox.Show("FaultException<ErroProcessamento> throw by service.\r\n Exception type: FaultException<ErroProcessamento>" +
                                        "\r\nReason:" + ex.Message +
                                        "\r\nCodigo:" + ex.Detail.Codigo +
                                        "\r\nMessagem:" + ex.Detail.Messagem +
                                        "\r\nData:" + ex.Detail.Data);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Exception throw by service.\r\n Exception type: " + ex.GetType().Name +
                                        "\r\nMessage:" + ex.Message);

                        ts.Dispose();
                    }
                    finally
                    {
                        client.Close();
                    }
                }
        }
Exemple #2
0
        private async void btnEnviar_Click(object sender, EventArgs e)
        {
            using (NotasServiceClient client =
                       new NotasServiceClient("WSHttpBinding_INotasService"))
            {
                var nota = new Nota()
                {
                    AlunoId      = (int)cboAluno.SelectedValue,
                    DisciplinaId = (int)cboDisciplina.SelectedValue,
                    Pontos       = Convert.ToDecimal(txtNota.Text)
                };

                await client.EnviarNotasAsync(nota);

                client.Close();
            }
        }