2017-08-31 114 views
1

我正尝试使用在系统上创建的本地用户连接到IBM MQ队列管理器。无法使用模拟加载mqe.dll

我使用赢服务器2008 R2,IBM MQ客户端和服务器版本是8.0.0.6

运行的代码,因为我已经实现了模拟一个本地用户。现在,当我模拟用户并尝试连接时,我会看到连接错误。当我作为一个不同的用户(本地用户)运行Visual Studio时,它可以工作,但不会在我使用模拟时使用。

下面是跟踪:

System.TypeInitializationException was unhandled 
    HResult=-2146233036 
    Message=The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception. 
    Source=amqmdnet 
    TypeName=IBM.WMQ.MQQueueManager 
    StackTrace: 
     at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, String Channel, String ConnName) 
     at MQExample.MQTest.ConnectMQ(String strQueueManagerName, String strQueueName, String strChannelInfo) in D:\Adidas\MQExample\MQExample\MQExample\MQTest.cs:line 83 
     at MQExample.Form1.button1_Click(Object sender, EventArgs e) in D:\Adidas\MQExample\MQExample\MQExample\Form1.cs:line 33 
     at System.Windows.Forms.Control.OnClick(EventArgs e) 
     at System.Windows.Forms.Button.OnClick(EventArgs e) 
     at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
     at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
     at System.Windows.Forms.Control.WndProc(Message& m) 
     at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
     at System.Windows.Forms.Button.WndProc(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.Run(Form mainForm) 
     at MQExample.Program.Main() in D:\Adidas\MQExample\MQExample\MQExample\Program.cs:line 19 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 
     HResult=-2146232828 
     Message=Exception has been thrown by the target of an invocation. 
     Source=mscorlib 
     StackTrace: 
      at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
      at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
      at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
      at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
      at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) 
      at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
      at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) 
      at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) 
      at IBM.WMQ.CommonServices.CreateCommonServices() 
      at IBM.WMQ.CommonServices.TraceConstructor(String objectId, String sccsid) 
      at IBM.WMQ.Nmqi.NmqiEnvironment..ctor(NmqiPropertyHandler nmqiPropertyHandler) 
      at IBM.WMQ.Nmqi.NmqiFactory.GetInstance(NmqiPropertyHandler properties) 
      at IBM.WMQ.MQQueueManager..cctor() 
     InnerException: 
      HResult=-2146232828 
      Message=Exception has been thrown by the target of an invocation. 
      Source=amqmdnet 
      StackTrace: 
       at IBM.WMQ.MQCommonServices..ctor() 
      InnerException: 
       HResult=-2146233088 
       Message=Failed to load mqe.dll from folder C:\Program Files\IBM\WebSphere MQ\bin\ 
       Source=amqmdnet 
       StackTrace: 
         at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode) 
       InnerException: 

代码来实现它:

using (new Tools.Impersonator("iibadmin", ".", "[email protected]")) 
        { 
         string userafter = WindowsIdentity.GetCurrent().Name; 
         MQQueueManager queueManager = null; 
         queueManager = new MQQueueManager(QueueManagerName, channelName, connectionName); 

         int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING; 
         queue = queueManager.AccessQueue(QueueName, openOptions); 
         int depth = queue.CurrentDepth; 
         queueMessage = new MQMessage(); 
         queueMessage.Format = MQC.MQFMT_STRING; 
         queueGetMessageOptions = new MQGetMessageOptions(); 
         queue.Get(queueMessage, queueGetMessageOptions); 
         strReturn = 
         queueMessage.ReadString(queueMessage.MessageLength); 
         queue.Close(); 

         queueManager.Disconnect(); 
        } 
+0

是否存在文件“C:\ Program Files \ IBM \ WebSphere MQ \ bin \ mqe.dll”?模拟的用户是否可以访问该文件?你想用模拟运行它的原因是什么?以这种方式使用模拟将指示队列管理器上的SVRCONN通道不安全,并且只是接受您在服务器上模拟的用户标识为有效的用户标识。使用MQv8,您可以向队列管理器发送用户名和密码,并且如果设置了验证并使用该ID来确定服务器上的MQ访问权限,则不需要模拟,并且由于您正在进行身份验证,所以安全性更好。 – JoshMc

+0

是否存在文件“C:\ Program Files \ IBM \ WebSphere MQ \ bin \ mqe.dll”?模拟的用户是否可以访问该文件? – JoshMc

+0

是的,它确实存在,模拟用户有权访问它。当Visual Studio作为不同的用户(本地用户,我冒充)运行时,它可以像黄油一样工作。当我假装它运行它时,这也是行不通的。我正在使用MQ版本8.0.0.6。 MQ服务器中的用户没有设置密码,它只有用户名。我不能只设置用户名并连接到MQueueManager。我希望你的意思是在hashtable属性中设置userid属性和密码。你可以让我知道,如果它可以用只有用户名完成? – Maddy

回答

0

你模拟的用户可能不具有MQ环境设置。

即环境变量:

PATH 
LIB 
MQ_JAVA_DATA_PATH 
MQ_JAVA_INSTALL_PATH 
MQ_JAVA_LIB_PATH 
MQ_JRE_PATH 

如果您运行的32位.NET,那么你需要指向32位MQ环境,比如聪明的64位。

即mqe.dll中发现:

C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll 
C:\Program Files\IBM\WebSphere MQ\bin64\mqe.dll 

因此,这是一个好主意,知道你需要设置你正在运行什么,什么MQ环境。

+0

如果不同的位(32-64)位是问题,它应该已经连接,当我运行VS作为不同的用户运行。我的系统中设置了MQ客户端。我如何检查用户的环境变量? – Maddy

+0

使用setmqenv命令。 https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.5.0/com.ibm.mq.ref.adm.doc/q083560_.htm – Roger