Esempio n. 1
0
        /// <summary>
        /// Send FinTS message
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="Message"></param>
        /// <returns></returns>
        public static string Send(string Url, string Message)
        {
            Log.Write("Connect to FinTS Server");
            Log.Write("Url: " + Url);

            // Warning:
            // This writes plain message incl. PIN, UserID and TAN human readable into a textfile!
            if (Trace.Enabled)
            {
                Trace.Write(Message);
            }

            try
            {
                var req = WebRequest.Create(Url) as HttpWebRequest;

                byte[] data = Encoding.ASCII.GetBytes(Helper.EncodeTo64(Message));

                req.Method        = "POST";
                req.Timeout       = 10000;
                req.ContentType   = "application/octet-stream";
                req.ContentLength = data.Length;
                req.KeepAlive     = false;

                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(data, 0, data.Length);
                    reqStream.Flush();
                }

                string FinTSMessage = string.Empty;

                using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                {
                    using (Stream resStream = res.GetResponseStream())
                    {
                        using (StreamReader streamReader = new StreamReader(resStream, Encoding.UTF8))
                        {
                            FinTSMessage = Helper.DecodeFrom64EncodingDefault(streamReader.ReadToEnd());
                        }
                    }
                }

                // Warning:
                // This writes plain message incl. PIN, UserID and TAN human readable into a textfile!
                if (Trace.Enabled)
                {
                    Trace.Write(FinTSMessage);
                }

                return(FinTSMessage);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Fehler beim Versenden der HBCI-Nachricht.", ex);
            }
        }
Esempio n. 2
0
        public static string Send(string Url, string Message)
        {
            Log.Write("Connect to FinTS Server");
            Log.Write("Url: " + Url);

            if (Trace.Enabled)
            {
                Trace.Write(Message);
            }

            try
            {
                var req = WebRequest.Create(Url) as HttpWebRequest;

                byte[] data = Encoding.ASCII.GetBytes(Helper.EncodeTo64(Message));

                req.Method        = "POST";
                req.Timeout       = 10000;
                req.ContentType   = "application/octet-stream";
                req.ContentLength = data.Length;
                req.KeepAlive     = false;

                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(data, 0, data.Length);
                    reqStream.Flush();
                }

                string FinTSMessage = string.Empty;

                using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                {
                    using (Stream resStream = res.GetResponseStream())
                    {
                        using (StreamReader streamReader = new StreamReader(resStream, Encoding.UTF8))
                        {
                            FinTSMessage = Helper.DecodeFrom64(streamReader.ReadToEnd());
                        }
                    }
                }

                if (Trace.Enabled)
                {
                    Trace.Write(FinTSMessage);
                }

                return(FinTSMessage);
            }
            catch (Exception ex)
            {
                Log.Write(ex.ToString());

                return(string.Empty);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Send FinTS message async
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="Message"></param>
        /// <returns></returns>
        private static async Task <string> SendAsync(FinTsClient client, string Message)
        {
            try
            {
                string FinTSMessage = string.Empty;
                ServicePointManager.SecurityProtocol = client.ConnectionDetails.SecurityProtocol;
                var req = WebRequest.Create(client.ConnectionDetails.Url) as HttpWebRequest;

                byte[] data = Encoding.ASCII.GetBytes(Helper.EncodeTo64(Message));

                req.Method        = "POST";
                req.Timeout       = 10000;
                req.ContentType   = "application/octet-stream";
                req.ContentLength = data.Length;
                req.KeepAlive     = false;

                using (var reqStream = await req.GetRequestStreamAsync())
                {
                    await reqStream.WriteAsync(data, 0, data.Length);

                    await reqStream.FlushAsync();
                }

                using (var res = (HttpWebResponse)await req.GetResponseAsync())
                {
                    using (var resStream = res.GetResponseStream())
                    {
                        using (var streamReader = new StreamReader(resStream, Encoding.UTF8))
                        {
                            FinTSMessage = Helper.DecodeFrom64EncodingDefault(streamReader.ReadToEnd());
                        }
                    }
                }

                // Warning:
                // This writes plain message incl. PIN, UserID and TAN human readable into a textfile!
                if (Trace.Enabled)
                {
                    if (Trace.MaskCredentials)
                    {
                        Trace.Write(FinTSMessage, client.ConnectionDetails.UserId, client.ConnectionDetails.Pin);
                    }
                    else
                    {
                        Trace.Write(FinTSMessage);
                    }
                }

                return(FinTSMessage);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Fehler beim Versenden der HBCI-Nachricht.", ex);
            }
        }