Exemple #1
0
        /// <summary>
        /// 处理getorders
        /// </summary>
        /// <param name="orders"></param>
        /// <returns></returns>
        public MessWms transGteorder(SapEkko[] orders)
        {
            StringUtil <SapEkko> pf = new StringUtil <SapEkko>();

            try
            {
                AppConfig.Cache.IsAutoCache   = false;
                AppConfig.Debug.OpenDebugInfo = true;

                foreach (SapEkko komodel in orders)
                {
                    _logInfo.Info("transGteorder", "单条表头\r\n" + pf.GetEntityToString(komodel));

                    SapEkpo[] pos = komodel._ekpos;


                    using (MAction action = new MAction("EKKO"))
                    {
                        if (action.Exists("Ebeln = '" + komodel.Ebeln + "'"))
                        {
                            _logInfo.Debug("transGteorder", "采购单号" + komodel.Ebeln + "重复传输!\r\n");
                            continue;
                        }
                        action.BeginTransation();

                        action.AllowInsertID = false;
                        //插入表头
                        action.Set("Ebeln", komodel.Ebeln);
                        action.Set("Bsart", komodel.Bsart);
                        action.Set("Unsez", komodel.Unsez);
                        action.Set("Ihrez", komodel.Ihrez);
                        action.Set("Lifnr", komodel.Lifnr);
                        action.Set("Ekogr", komodel.Ekogr);
                        action.Set("Ekgrp", komodel.Ekgrp);
                        action.Set("Bukrs", komodel.Bukrs);
                        action.Set("Zcomment", komodel.Zcomment);
                        action.Set("Ernam", komodel.Ernam);
                        action.Set("Aedat", komodel.Aedat);

                        action.Set("pflag", "N");
                        action.Set("ts", DateTime.Now);

                        bool issuccess = action.Insert(true);
                        //写日志
                        _logInfo.Debug("transGteorder", komodel.Ebeln + action.DebugInfo + "\r\n");

                        //插入明细表
                        action.ResetTable("Ekpo", true);
                        foreach (SapEkpo pomodel in pos)
                        {
                            StringUtil <SapEkpo> po = new StringUtil <SapEkpo>();
                            _logInfo.Info("transGteorder", "单条明细\r\n" + po.GetEntityToString(pomodel));
                            if (pomodel == null)
                            {
                                throw new Exception("传输失败,明细为null");
                            }
                            action.Set("Ebelp", pomodel.Ebelp);
                            action.Set("Pstyp", pomodel.Pstyp);
                            action.Set("Matnr", pomodel.Matnr);
                            action.Set("Txz01", pomodel.Txz01);
                            action.Set("Menge", pomodel.Menge);
                            action.Set("Meins", pomodel.Meins);
                            action.Set("Gewei", pomodel.Gewei);
                            action.Set("Emren", pomodel.Emren);
                            action.Set("Umrez", pomodel.Umrez);
                            action.Set("Eindt", pomodel.Eindt);
                            action.Set("Netpr", pomodel.Netpr);
                            action.Set("Waers", pomodel.Waers);
                            action.Set("Peinh", pomodel.Peinh);
                            action.Set("Bprme", pomodel.Bprme);
                            action.Set("Mwskz", pomodel.Mwskz);
                            action.Set("Matkl", pomodel.Matkl);
                            action.Set("Retpo", pomodel.Retpo);
                            action.Set("Repos", pomodel.Repos);
                            action.Set("Werks", pomodel.Werks);
                            action.Set("Lgort", pomodel.Lgort);
                            action.Set("Brtwr", pomodel.Brtwr);

                            action.Set("Ebeln", komodel.Ebeln);
                            action.Set("pflag", "N");
                            action.Insert();
                        }

                        action.EndTransation();
                    }
                }
            }
            catch (Exception ex)
            {
                _logInfo.Error("transGteorder", ex.ToString() + "\r\n");
                return(new MessWms()
                {
                    TYPE = MessWms.failure,
                    Mess = "处理失败!" + ex.Message
                });
            }
            return(new MessWms()
            {
                TYPE = MessWms.success,
                Mess = "处理成功!"
            });
        }
Exemple #2
0
        public String executeHTTPMethod(GatewayApiRequest gatewayApiRequest)
        {
            string body = String.Empty;

            GatewayApiConfig GatewayApiConfig = gatewayApiRequest.GatewayApiConfig;


            //proxy settings
            if (GatewayApiConfig.UseProxy)
            {
                WebProxy proxy = new WebProxy(GatewayApiConfig.ProxyHost, true);
                if (!String.IsNullOrEmpty(GatewayApiConfig.ProxyUser))
                {
                    if (String.IsNullOrEmpty(GatewayApiConfig.ProxyDomain))
                    {
                        proxy.Credentials = new NetworkCredential(GatewayApiConfig.ProxyUser, GatewayApiConfig.ProxyPassword);
                    }
                    else
                    {
                        proxy.Credentials = new NetworkCredential(GatewayApiConfig.ProxyUser, GatewayApiConfig.ProxyPassword, GatewayApiConfig.ProxyDomain);
                    }
                }
                WebRequest.DefaultWebProxy = proxy;
            }

            // Create the web request
            HttpWebRequest request = WebRequest.Create(gatewayApiRequest.RequestUrl) as HttpWebRequest;

            //http verb
            request.Method = gatewayApiRequest.ApiMethod;

            //content type, json, form, etc
            request.ContentType = gatewayApiRequest.ContentType;

            LogInfo.Information($@"HttpWebRequest url {gatewayApiRequest.RequestUrl} method {request.Method}");


            //Authentication setting
            if (GatewayApiConfig.AuthenticationByCertificate)
            {
                //custom implementation fo SSL certificate validation callback
                request.ServerCertificateValidationCallback +=
                    (sender, cert, chain, error) =>
                {
                    return(error == SslPolicyErrors.None || (error != SslPolicyErrors.None && GatewayApiConfig.IgnoreSslErrors));
                };

                //create a new certificate collection
                X509Certificate2Collection certificates = new X509Certificate2Collection();

                //load and add a new certificate loaded from file (p12)
                certificates.Add(new X509Certificate2(new X509Certificate(GatewayApiConfig.CertificateLocation, GatewayApiConfig.CertificatePassword)));

                //attach certificate to request
                request.ClientCertificates = certificates;
            }
            else
            {
                string credentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(GatewayApiConfig.Username + ":" + GatewayApiConfig.Password));
                request.Headers.Add("Authorization", "Basic " + credentials);
            }

            //buuld the request
            try
            {
                if ((gatewayApiRequest.ApiMethod == "PUT" || gatewayApiRequest.ApiMethod == "POST") &&
                    !String.IsNullOrEmpty(gatewayApiRequest.Payload))
                {
                    LogInfo.Information($@"HttpWebRequest payload {gatewayApiRequest.Payload}");

                    // Create a byte array of the data we want to send
                    byte[] utf8bytes    = Encoding.UTF8.GetBytes(gatewayApiRequest.Payload);
                    byte[] iso8859bytes = Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("iso-8859-1"), utf8bytes);

                    // Set the content length in the request headers
                    request.ContentLength = iso8859bytes.Length;

                    // Write request data
                    using (Stream postStream = request.GetRequestStream())
                    {
                        postStream.Write(iso8859bytes, 0, iso8859bytes.Length);
                    }
                }

                // Get response
                try
                {
                    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                    {
                        // Get the response stream
                        StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("iso-8859-1"));
                        body = reader.ReadToEnd();
                    }
                }
                catch (WebException wex)
                {
                    LogInfo.Debug($@"Response debug : {wex.Response.Headers}");
                    StreamReader reader = new StreamReader(wex.Response.GetResponseStream(), Encoding.GetEncoding("iso-8859-1"));
                    body = reader.ReadToEnd();
                }

                LogInfo.Information($@"HttpWebResponse response {body}");

                return(body);
            }
            catch (Exception ex)
            {
                return(ex.Message + "\n\naddress:\n" + request.Address.ToString() + "\n\nheader:\n" + request.Headers.ToString() + "data submitted:\n" + gatewayApiRequest.Payload);
            }
        }