public LookupTableClient CreateLookupTableClient()
        {
            _lookupTableClient = new LookupTableClient(_binding, _endpointAddress);
            SetCredenticalProperties <LookupTableClient, LookupTable>(_lookupTableClient);

            return(_lookupTableClient);
        }
        /// <summary>
        /// Metodo para criar as Lookuptable e suas dependencias
        /// </summary>
        /// <param name="pwaDestino">Destino</param>
        /// <param name="itemRow">Item CustomField</param>
        /// <param name="ds">Data Set LookupTable</param>
        public void CreateLooukupTable(string pwaOrigem, string pwaDestino, string pLT_NAME)
        {
            try
            {
                //verificando se já existe a lookuptable no destino
                dsLookupTableDestino = GetLookupTable(pwaDestino);

                DataRow[] dataRowDestino = dsLookupTableDestino.Tables[0].Select("LT_NAME = '" + pLT_NAME + "'");

                if (dataRowDestino.Count() > 0)
                {
                    return;
                }

                if (dsLookupTableOrigem == null)
                {
                    dsLookupTableOrigem = GetLookupTable(pwaOrigem);
                }

                DataRow[] dataRow = dsLookupTableOrigem.Tables[0].Select("LT_NAME = '" + pLT_NAME + "'");

                SvcLookupTable.LookupTableDataSet ltDS = new LookupTableDataSet();

                SvcLookupTable.LookupTableClient clientLookupTable = new LookupTableClient(Binding, endPointAdress(pwaDestino, "/_vti_bin/psi/LookupTable.asmx"));
                clientLookupTable.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain);

                foreach (SvcLookupTable.LookupTableDataSet.LookupTablesRow item in dataRow)
                {
                    SvcLookupTable.LookupTableDataSet.LookupTablesRow ltRow = ltDS.LookupTables.NewLookupTablesRow();
                    Guid LT_UID = Guid.NewGuid();

                    ltRow.LT_UID = LT_UID;

                    ltRow.LT_FILL_ALL_LEVELS = item.LT_FILL_ALL_LEVELS;
                    ltRow.LT_NAME            = item.LT_NAME;

                    if (!item.IsAPP_ENTITY_UIDNull())
                    {
                        ltRow.APP_ENTITY_UID = item.APP_ENTITY_UID;
                    }

                    if (!item.IsLT_PRIMARY_LCIDNull())
                    {
                        ltRow.LT_PRIMARY_LCID = item.LT_PRIMARY_LCID;
                    }

                    if (!item.IsLT_SORT_ORDER_ENUMNull())
                    {
                        ltRow.LT_SORT_ORDER_ENUM = item.LT_SORT_ORDER_ENUM;
                    }

                    ltDS.LookupTables.Rows.Add(ltRow);


                    foreach (SvcLookupTable.LookupTableDataSet.LookupTableMasksRow itemMaskRow in dsLookupTableOrigem.LookupTableMasks.Select("LT_UID = '" + item.LT_UID + "'"))
                    {
                        SvcLookupTable.LookupTableDataSet.LookupTableMasksRow ltMasksRow = ltDS.LookupTableMasks.NewLookupTableMasksRow();
                        foreach (DataColumn itemColumn in dsLookupTableOrigem.LookupTableMasks.Columns)
                        {
                            if (!ltDS.LookupTableMasks.Columns.Contains(itemColumn.ToString()))
                            {
                                continue;
                            }

                            if (itemColumn.ToString() == "LT_UID")
                            {
                                ltMasksRow[itemColumn.ToString()] = LT_UID;
                                continue;
                            }

                            if (itemMaskRow[itemColumn.ToString()] != null && !itemColumn.ReadOnly)
                            {
                                ltMasksRow[itemColumn.ToString()] = itemMaskRow[itemColumn.ToString()];
                            }
                        }

                        //ltMasksRow.LT_MASK_STRUCT_LEVEL = itemMaskRow.LT_MASK_STRUCT_LEVEL;
                        //ltMasksRow.LT_MASK_STRUCT_TYPE_ENUM = itemMaskRow.LT_MASK_STRUCT_TYPE_ENUM;
                        //ltMasksRow.LT_MASK_STRUCT_LENGTH = itemMaskRow.LT_MASK_STRUCT_LENGTH;
                        //ltMasksRow.LT_MASK_VALUE_SEPARATOR = itemMaskRow.LT_MASK_VALUE_SEPARATOR;

                        ltDS.LookupTableMasks.Rows.Add(ltMasksRow);
                    }



                    foreach (SvcLookupTable.LookupTableDataSet.LookupTableTreesRow itemTreesRow in dsLookupTableOrigem.LookupTableTrees.Select("LT_UID = '" + item.LT_UID + "'"))
                    {
                        //ltTreesRow.LT_UID = ltDS.LookupTables[0].LT_UID;
                        SvcLookupTable.LookupTableDataSet.LookupTableTreesRow ltTreesRow = ltDS.LookupTableTrees.NewLookupTableTreesRow();
                        foreach (DataColumn itemColumn in dsLookupTableOrigem.LookupTableTrees.Columns)
                        {
                            if (!ltDS.LookupTableTrees.Columns.Contains(itemColumn.ToString()))
                            {
                                continue;
                            }

                            //if (itemColumn.ToString() == "LT_STRUCT_UID")
                            //{
                            //    ltTreesRow[itemColumn.ToString()] = Guid.NewGuid();
                            //    continue;
                            //}

                            if (itemColumn.ToString() == "LT_UID")
                            {
                                ltTreesRow[itemColumn.ToString()] = LT_UID;
                                continue;
                            }


                            if (itemTreesRow[itemColumn.ToString()] != null && !itemColumn.ReadOnly)
                            {
                                ltTreesRow[itemColumn.ToString()] = itemTreesRow[itemColumn.ToString()];
                            }
                        }

                        ltDS.LookupTableTrees.Rows.Add(ltTreesRow);
                    }

                    try
                    {
                        bool validateOnly = false;
                        bool autoCheckIn  = true;

                        clientLookupTable.CreateLookupTables(ltDS, validateOnly, autoCheckIn);
                    }
                    catch (SoapException ex)
                    {
                        string errMess = "";
                        // Pass the exception to the PSClientError constructor to
                        // get all error information.
                        PSLibrary.PSClientError psiError  = new PSLibrary.PSClientError(ex);
                        PSLibrary.PSErrorInfo[] psiErrors = psiError.GetAllErrors();

                        for (int j = 0; j < psiErrors.Length; j++)
                        {
                            errMess += psiErrors[j].ErrId.ToString() + "\n";
                        }
                        errMess += "\n" + ex.Message.ToString();

                        MessageBox.Show(errMess);
                        // Send error string to console or message box.
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }