簡體   English   中英

如何以編程方式在專用MSMQ隊列上設置權限設置以進行遠程訪問?

[英]How to programmatically set Permission settings on private MSMQ queue for remote access?

作為我正在開發的應用程序的一部分,我試圖利用Microsoft消息隊列功能,但遇到權限設置問題。

我想創建一個隊列,並在服務器計算機上向它發送消息,然后通過本地網絡從客戶端計算機訪問它。 兩台計算機(均為Windows 7 Home Premium)都在同一LAN網絡上,並且能夠相互ping通。 我將知道所創建隊列的確切路徑,所以我猜私有隊列是可以的。

我將代碼基於此示例,並使用IronPython從System.Messaging命名空間訪問MessageQueue類 該示例中的發送和接收設置可在一個控制台中創建隊列並向其發送消息:

>>> localQueue = MessageQueue.Create('.\\private$\\testQueue')
>>> localQueue.FormatName
'DIRECT=OS:<clientMachineName>\\private$\\testQueue'
>>> localQueue.Send('hello from other console')

然后通過以下代碼訪問該隊列並在另一個控制台中進行查看:

>>> SemiRemoteQueue = MessageQueue('FormatName:Direct=OS:<clientMachineName>\\private$\\testQueue')
>>> SemiRemoteQueue.Peek()
<System.Messaging.Message object at 0x000000000000002F [System.Messaging.Message
]>

當我在服務器計算機上創建新隊列時,似乎可以從客戶端計算機建立連接,但是無法從該計算機獲取任何消息數據。 從客戶端瀏覽到在服務器上創建的隊列,將顯示以下“訪問被拒絕”錯誤消息:

>>> ReallyRemoteQueue = MessageQueue('FormatName:Direct=OS:<serverMachineName>\\private$\\remoteTestQueue')
>>> ReallyRemoteQueue.Peek()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
EnvironmentError: System.Messaging.MessageQueueException (0x80004005): Access to
 Message Queuing system is denied.
   at System.Messaging.MessageQueue.MQCacheableInfo.get_ReadHandle()
   at System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32 timeout, Int3
2 action, MQPROPS properties, NativeOverlapped* overlapped, ReceiveCallback rece
iveCallback, CursorHandle cursorHandle, IntPtr transaction)
   at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 actio
n, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction in
ternalTransaction, MessageQueueTransactionType transactionType)
   at System.Messaging.MessageQueue.Peek()
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame
 frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T
1 arg1, T2 arg2)
   at IronPython.Compiler.Ast.CallExpression.Invoke0Instruction.Run(InterpretedF
rame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 a
rg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Hosting.PythonCommandLine.<>c__DisplayClass1.<RunOneInteraction
>b__0()

我發現應該可以訪問遠程專用MSMQ隊列,但無法弄清楚如何設置正確的權限。 我已經在防火牆設置中允許使用MSMQ,甚至嘗試關閉防火牆。 找到了一些有關將權限設置應用於隊列文件的討論,但這無濟於事,因為我沒有具有適用於它們的安全設置的隊列文件。 我還沒有嘗試過建議完全授予“匿名登錄”訪問權限的選項,但最終還是希望通過編程方式(在代碼中)而不是在文件的上下文菜單中設置權限。 我應該在MessageQueing類(http://msdn.microsoft.com/zh-cn/library/dd48yz36(v=vs.80))中使用SetPermissions方法嗎? 如何指定其參數?

感謝您的任何建議!

localQueue.SetPermissions(“每個人”,MessageQueueAccessRights.FullControl,AccessControlEntryType.Allow);

“每個人”可以是任何域帳戶,例如“ Domain \\ MyUserName”

首先,您需要授予“匿名登錄”權限,以從隊列接收消息。

我使用此(C#)代碼設置權限,該代碼在這里找到:

AccessControlList acl = new AccessControlList();
Trustee owner = new Trustee(WindowsIdentity.GetCurrent().Name, Environment.MachineName, TrusteeType.User);
MessageQueueAccessControlEntry aceOwner = new MessageQueueAccessControlEntry(owner, MessageQueueAccessRights.FullControl);
acl.Add(aceOwner);
messageQueue.SetPermissions(acl);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM