示例#1
0
        static void Main(string[] args)
        {
            Axapta Ax = new Axapta();

            Ax.Logon(null, null, null, null);
            string className  = "ZFS_TestXML";
            string methodName = "getResultTable";
            string paramList  = null;

            AxaptaObject axObj = Ax.CreateAxaptaObject(className);
            AxaptaRecord ret   = null;

            if (paramList != null)
            {
                ret = (AxaptaRecord)axObj.Call(methodName, paramList);
            }
            else
            {
                ret = (AxaptaRecord)axObj.Call(methodName);
            }

            while (ret.Found)
            {
                ret.get_Field(2);
            }

            axObj.Dispose();
        }
示例#2
0
        /// <summary>
        /// Creates the XML schema
        /// </summary>
        /// <param name="className">Class name</param>
        /// <param name="methodName">Method name</param>
        /// <param name="paramList">Parameters list</param>
        /// <returns></returns>
        public Byte[] GetAxDataCreateSchema(string className, string methodName, params object[] paramList)
        {
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                //this.AxLogin();
                this.AxLoginAs();
                AxaptaObject axObj = Ax.CreateAxaptaObject(className);
                string       ret   = (string)this.callMethod(className, methodName, paramList);

                //converto la stringa in XML document
                xmlDoc.LoadXml(ret);

                //creo un reader di dati XML per popolare il dataset
                XmlNodeReader       xmlReader = new XmlNodeReader(xmlDoc.DocumentElement);
                System.Data.DataSet ds        = new System.Data.DataSet();

                //carico il dataset coi dati XML (Carico lo schema)
                ds.ReadXml(xmlReader, System.Data.XmlReadMode.InferSchema);

                //comprimo il dataset compreso di schema con GZIP e restituisco un byte array
                MemoryStream ms = new MemoryStream();
                System.IO.Compression.GZipStream zip = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress);
                ds.WriteXml(zip, System.Data.XmlWriteMode.WriteSchema);
                zip.Close();
                ms.Close();
                axObj.Dispose();

                return(ms.GetBuffer());
            }
            catch (Microsoft.Dynamics.AxaptaException ex)
            {
                this.WriteErrorToEventLog(ex);
                SoapException se = new SoapException(ex.Message, SoapException.ServerFaultCode, ex.InnerException);
                throw se;
            }
            catch (Exception ex)
            {
                this.WriteErrorToEventLog(ex);
                SoapException se = new SoapException(ex.Message, SoapException.ClientFaultCode, ex.InnerException);
                throw se;
            }
            finally
            {
                this.AxLogoff();
            }
        }
示例#3
0
        /// <summary>
        /// Calls an AX method
        /// </summary>
        /// <param name="className">Class name</param>
        /// <param name="methodName">Method name</param>
        /// <param name="paramList">Parameters list</param>
        /// <returns></returns>
        private Object callMethod(string className, string methodName, params object[] paramList)
        {
            AxaptaObject axObj = Ax.CreateAxaptaObject(className);
            Object       ret   = null;

            if (paramList != null)
            {
                ret = axObj.Call(methodName, paramList);
            }
            else
            {
                ret = axObj.Call(methodName);
            }

            axObj.Dispose();

            return(ret);
        }
示例#4
0
        //public AxConnectorServer(System.Security.Principal.IIdentity curUserIdentity)
        //{
        //    userIdentity = curUserIdentity;
        //}

        //public AxConnectorServer()
        //{

        //}

        //Metodo che legge lo schema restituito ad AX

        /// <summary>
        /// Queries Ax
        /// </summary>
        /// <param name="className">Class name</param>
        /// <param name="methodName">Method name</param>
        /// <param name="paramList">Parameter list</param>
        /// <returns></returns>
        public Byte[] GetAxData(string className, string methodName, params object[] paramList)
        {
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                //this.AxLogin();
                this.AxLoginAs();
                AxaptaObject axObj = Ax.CreateAxaptaObject(className);
                string       ret   = (string)this.callMethod(className, methodName, paramList);

                Byte[] buf = Encoding.UTF8.GetBytes(ret);

                MemoryStream ms = new MemoryStream();
                System.IO.Compression.GZipStream zip = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress);
                zip.Write(buf, 0, buf.Length);
                zip.Close();
                ms.Close();
                axObj.Dispose();

                return(ms.GetBuffer());
            }
            catch (Microsoft.Dynamics.AxaptaException ex)
            {
                this.WriteErrorToEventLog(ex);
                SoapException se = new SoapException(ex.Message, SoapException.ServerFaultCode, ex.InnerException);
                throw se;
            }
            catch (Exception ex)
            {
                this.WriteErrorToEventLog(ex);
                SoapException se = new SoapException(ex.Message, SoapException.ClientFaultCode, ex.InnerException);
                throw se;
            }
            finally
            {
                this.AxLogoff();
            }
        }