Ошибка ссылки на объект при создании экземпляра объекта - PullRequest
0 голосов
/ 23 ноября 2011
private void PerformWork(object state)
    {
        try
            {
                MMS.MMSService.Console.Program _program = new MMS.MMSService.Console.Program();
                _program.OUIProcess();
            }

            catch (Exception ex)
            {
                eventLog1.WriteEntry(ex.Message);
            }
        }

Я получаю ошибку ссылки на объект для _program, которую я не могу выяснить.Пожалуйста, помогите мне?

Вот код:

public class Program
{
    // The type of connection to use, this can be:-
    // MQC.TRANSPORT_MQSERIES_BINDINGS for a server connection.
    // MQC.TRANSPORT_MQSERIES_CLIENT for a non-XA client connection
    // MQC.TRANSPORT_MQSERIES_XACLIENT for an XA client connection
    // MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection
    const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;

    // Define the name of the queue manager to use (applies to all connections)
    static String qManager = ConfigurationManager.AppSettings["qManager"].ToString();

    // Define the name of your host connection (applies to client connections only)
    static String hostName = ConfigurationManager.AppSettings["hostName"].ToString();

    // Define the name of the channel to use (applies to client connections only)
    static String channel = ConfigurationManager.AppSettings["channel"].ToString();

    public Program()
    {

        // The type of connection to use, this can be:-
        // MQC.TRANSPORT_MQSERIES_BINDINGS for a server connection.
        // MQC.TRANSPORT_MQSERIES_CLIENT for a non-XA client connection
        // MQC.TRANSPORT_MQSERIES_XACLIENT for an XA client connection
        // MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection
        const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;

        // Define the name of the queue manager to use (applies to all connections)
        String qManager = ConfigurationManager.AppSettings["qManager"].ToString();

        // Define the name of your host connection (applies to client connections only)
        String hostName = ConfigurationManager.AppSettings["hostName"].ToString();

        // Define the name of the channel to use (applies to client connections only)
        String channel = ConfigurationManager.AppSettings["channel"].ToString();

    }
    static Hashtable init()
    {
        Hashtable connectionProperties = new Hashtable();
        connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);
        connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
        connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
        return connectionProperties;
    }

    /// <summary>
    /// The main entry point for the application.
    /// </summary>

    public void OUIProcess()
    {
        try
        {
            NRTManager ouiManager = new NRTManager();

            Hashtable connectionProperties = init();

            // Create a connection to the queue manager using the connection
            // properties just defined
            MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);

            // Set up the options on the queue we want to open
            int openOptions = MQC.MQOO_INPUT_SHARED  | MQC.MQGMO_BROWSE_FIRST;

            // Now specify the queue that we want to open,and the open options
            MQQueue system_default_local_queue =
            qMgr.AccessQueue(ConfigurationManager.AppSettings["queue"].ToString(), openOptions);

            // First define a WebSphere MQ message buffer to receive the message
            MQMessage retrievedMessage = new MQMessage();
            retrievedMessage.MessageId = MQC.MQMI_NONE;

            // Set the get message options
            MQGetMessageOptions gmo = new MQGetMessageOptions(); //accept the defaults

            // Get the message off the queue
            system_default_local_queue.Get(retrievedMessage, gmo);

            // Prove we have the message by displaying the UTF message text
            string msgText = retrievedMessage.ReadString(retrievedMessage.DataLength);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(msgText);

            ouiManager.WriteToOUIdb(0, "Message Pulled", doc, ConfigurationManager.ConnectionStrings["OUI"].ConnectionString, ConfigurationManager.ConnectionStrings["MMS"].ConnectionString);

            //Close the queue
            system_default_local_queue.Close();

            // Disconnect from the queue manager
            qMgr.Disconnect();
        }

        //If an error has occurred in the above,try to identify what went wrong.

        //Was it a WebSphere MQ error?
        catch (MQException ex)
        {
            Logging logger = new Logging();
            logger.WriteToLog(1, ex.ToString(), null, null, ConfigurationManager.ConnectionStrings["MMS"].ConnectionString);
        }

        catch (System.Exception ex)
        {
            Logging logger = new Logging();
            logger.WriteToLog(1, ex.ToString(), null, null, ConfigurationManager.ConnectionStrings["MMS"].ConnectionString);
        }

    }//end of start

    public static void ValidationHandler(object sender, ValidationEventArgs e)
    {
        //WriteToLog(1, e.ToString(), null, null);
        //Console.WriteLine(e.Message);
    }
}

1 Ответ

1 голос
/ 23 ноября 2011

Я подозреваю, что один из ваших параметров конфигурации отсутствует. Убедитесь, что они все присутствуют и правильно. Обратите внимание, что вызов ToString с нулевым значением вызовет исключение, которое вы видите.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...