Ejemplo n.º 1
0
        public static ClientInterfaceServiceClient CreateServiceProxy(string url, string username, string password)
        {
            var basicHttpBinding = CreateBasicHttpBinding();
            var endpointAddress  = new EndpointAddress(url);

            var client = new ClientInterfaceServiceClient(basicHttpBinding, endpointAddress);

            client.ClientCredentials.UserName.UserName = username;
            client.ClientCredentials.UserName.Password = password;

            return(client);
        }
        public async Task Execute()
        {
            if (Invoice == null)
            {
                throw new ArgumentNullException("Invoice boş olamaz!");
            }


            _serviceProxy = InnovaHelper.CreateServiceProxy(ServiceInfo.ServiceUrl, ServiceInfo.UserName, ServiceInfo.Password);

            SendInvoicesRawRequest request = new SendInvoicesRawRequest()
            {
                Invoices = new[]
                {
                    new OutgoingInvoiceRaw()
                    {
                        Header = new OutgoingInvoiceHeader()
                        {
                            ReceiverAlias = this.ServiceInfo.ReceiverPostboxName,
                            SenderAlias   = this.ServiceInfo.ReceiverPostboxName
                        }
                    }
                }
            };

            await _serviceProxy.SendInvoicesRawAsync(request)
            .ContinueWith(d => {
                var result = new ServiceResponse()
                {
                    Hatali = false,
                };

                if (d.IsCanceled || d.IsFaulted)
                {
                    result.Hatali = true;
                    foreach (System.Exception innerException in d.Exception.Flatten().InnerExceptions)
                    {
                        result.Istisna += innerException.ToString();
                    }
                }
                else
                {
                    result.Sonuc = d.IsCompletedSuccessfully ? "İşlem başarıyla tamamlandı" : "İşlem tamamlandı!";
                    result.Data  = new { d.Result };
                }

                return(result);
            });
        }