Esempio n. 1
0
        string ExecuteWebService(string xmlFile, string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(string.Empty);
            }

            var parts  = Path.GetFileNameWithoutExtension(xmlFile).Split('.');
            var accion = parts[2];

            DataTable dt = new DataTable();

            dt.ReadXml(xmlFile);

            SincroDBService.SincroDBServiceSoapClient client = new SincroDBService.SincroDBServiceSoapClient();
            client.Endpoint.Address = new System.ServiceModel.EndpointAddress(url);

            var method = client.GetType().GetMethods().Where(o => o.ReturnType == typeof(string) && o.Name.Contains(dt.TableName)).FirstOrDefault();

            if (method == null)
            {
                throw new Exception($"El metodo de la tabla: {dt.TableName}, no encontrado!");
            }

            List <object> args = new List <object>();

            foreach (var p in method.GetParameters())
            {
                if (p.Name.Equals("RowGuid"))
                {
                    var prefix = accion.Equals("Delete") ? "@" : string.Empty;
                    args.Add($"{prefix}{dt.Rows[0][p.Name].ToString()}");
                }
                else
                {
                    if (dt.Columns.Contains(p.Name))
                    {
                        args.Add(dt.Rows[0][p.Name]);
                    }
                    else
                    {
                        foreach (DataColumn col in dt.Columns)
                        {
                            if (String.Compare(p.Name, col.ColumnName, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) == 0)
                            {
                                args.Add(dt.Rows[0][col.ColumnName]);
                            }
                        }
                    }
                }
            }

            return(Convert.ToString(method.Invoke(client, args.ToArray())));
        }
Esempio n. 2
0
        private void bSyncNow_Click(object sender, EventArgs e)
        {
            var key = ConfigurationManager.AppSettings.Get("UsarWebServices");

            SincroDBService.SincroDBServiceSoapClient clint = new SincroDBService.SincroDBServiceSoapClient();
            //  clint.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://181.123.14.83/SincroDBService.asmx");
            var methods = clint.GetType().GetMethods();

            var dts     = (List <Element>)gvServerB.DataSource;
            var element = dts[0];

            MethodInfo method = methods.Where(o => o.ReturnType == typeof(string) && o.Name.Contains(element.TableName)).FirstOrDefault();

            DataTable dt = new DataTable();

            dt.ReadXml(element.FullName);

            List <object> parameter = new List <object>();

            foreach (var p in method.GetParameters())
            {
                parameter.Add(dt.Rows[0][p.Name]);
            }

            //   method.Invoke(clint, parameter.ToArray());

            var thread = new Thread(() =>
            {
                for (int i = 0; i < 1000; i++)
                {
                    Thread.Sleep(1000);
                    Invoke(new Action(() =>
                    {
                        lblStatus.Text = i.ToString();
                    }));
                }
            });

            thread.Start();
        }