Exemple #1
0
        private int InvokeID             = 1; // Holds the unique Invoke ID for each XML request

        /* Sets the client, writer and reader variables of XMLHandler class with the respective SocketHandler class variables*/
        public void setParameters(SocketHandler socket_handle)
        {
            client = socket_handle.TcpClient;
            writer = socket_handle.SocketWriter;
            reader = socket_handle.SocketReader;
        }
Exemple #2
0
        /* This function starts an application session with the AE Services server and returns a
         * session ID to uniquely identify the session.
         */
        public string StartApplicationSession(string server_ip, int server_port, bool isSecure, string username, string password, string protocol_version)
        {
            try
            {
                /*
                 * Create TCP socket and attach stream Reader and Writer. This reader and writer
                 * will be used to read response data and write request data respectively
                 * */
                socket_handle = new SocketHandler();

                Console.WriteLine("Connecting to AE Services Server..");
                if (socket_handle.openSocket(server_ip, server_port, isSecure))
                {
                    Console.WriteLine("Socket open operation performed successfully");
                    xmlHandler = new XMLHandler();
                    xmlHandler.setParameters(socket_handle);
                }
                else
                {
                    Console.WriteLine("Error encountered during socket open operation.\n" +
                                      "Please check IP address and port for the AE Services server");
                    if (isSecure)
                    {
                        Console.WriteLine("Ensure that the secure port is enabled");
                    }
                    else
                    {
                        Console.WriteLine("Ensure that the non-secure port is enabled");
                    }

                    Console.ReadKey();
                    Environment.Exit(1);
                }

                // Get the XML string for the "StartApplicationSession" request and send the request
                xmlHandler.sendRequest(XMLFormatter.FormatStartAppSessionRequest(username, password, protocol_version));

                // Read the response
                string response = xmlHandler.readXMLMessage();

                // parse the response and create a document node tree structure for accessing XML data
                XmlDocument doc = new XmlDocument();

                if (response.Contains("StartApplicationSessionPosResponse"))
                {
                    doc.LoadXml(response);
                    XmlElement  root      = doc.DocumentElement;
                    XmlNodeList NodeList  = root.GetElementsByTagName("sessionID");
                    string      sessionID = NodeList[0].InnerText;
                    return(sessionID);
                }
                else
                {
                    /* Parsing the reason for the reception of "StartApplicationSessionNegResponse" response
                     */
                    doc.LoadXml(response);
                    XmlElement  root     = doc.DocumentElement;
                    XmlNodeList NodeList = root.GetElementsByTagName("errorCode");
                    if (NodeList.Count > 0)
                    {
                        string errorResponse = NodeList[0].InnerText;
                        Console.WriteLine("Received error response for StartApplicationSession:\n {0}", errorResponse);
                        return(null);
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception at StartApplicationSession:\n {0}", ex.Message);
                return(null);
            }
        }