2012-03-08 4 views
0

내 MSMQ에서 메시지 수를 얻으려고합니다. 내가 인터넷에이 코드를 발견했다 (여러 번) :MSMQ Com에서 내 대기열을 찾을 수 없습니다.

// setup the queue management COM stuff 
MSMQManagement _queueManager = new MSMQManagement(); 

object machine = "MyLaptopComputer"; 
object path = @"DIRECT=OS:MyLaptopComputer\PRIVATE$\MyQueue"; 

_queueManager.Init(ref machine, ref path); 

Console.WriteLine(_queueManager.MessageCount); 

Marshal.ReleaseComObject(_queueManager); 

가이 오류와 함께 실패 내가 _queueManager.Init를 얻을 때마다 : 나는 확인했다

The queue path name specified is invalid.

(더블 체크) 내 대기열 이름 그것이 틀린 지보기 위해서. 다른 대기열, 다른 컴퓨터, 원격 실행, 로컬 실행 중 ... 시도하지 않았습니다. 아무 것도 작동하지 않습니다.

위 코드의 변형도 시도해 보았습니다. 예를 들어 나는 시도했다 : 나는 그들에 액세스 할 수 NServiceBus를 사용할 때

_queueManager.Init("MyLaptopComputer", @"DIRECT=OS:MyLaptopComputer\PRIVATE$\MyQueue"); 

큐는 NServiceBus과 기능을 잘 사용됩니다.

누구나 아이디어를 얻을 수 있습니까?

+1

"localhost"또는 "."을 (를) 사용해 보셨나요? 경로에 명시된 컴퓨터 이름 대신에? –

+0

@SeanH "시도했습니다.". 그러나, 나는 조금 더 오래 포기하기 전에 노력 했어야했다. 내 작업 변화를 보려면 아래 내 대답을 참조하십시오. – Vaccano

+0

왜 COM 클래스에 완벽하게 좋은 Api가있을 때 COM 클래스를 사용하고 있습니까? 닷넷 프레임 워크는 C#을 사용하고 있기 때문에? –

답변

1

내가보기에 문제는 약간의 오해입니다. MSMQManagement.Init은 3 개의 매개 변수를 사용합니다. 그것들은 모두 선택적입니다. 다른 언어 (예 : VB)에서는 2 개의 매개 변수로만 호출되는 경우가 있습니다.

당신이 C#으로하고있는 일을하는 방법을 보여줍니다 CodeProject project 있습니다 :

private int GetMessageCount(string queueName) 
{ 
    int count = 0; 
    try 
    { 

     MSMQ.MSMQManagement mgmt = new MSMQ.MSMQManagement(); 
     MSMQ.MSMQOutgoingQueueManagement outgoing; 
     String s = "YOURPCNAME"; 
     Object ss = (Object)s; 
     String pathName = queueName; 
     Object pn = (Object)pathName; 
     String format = null; 
     Object f = (Object)format; 

     mgmt.Init(ref ss , ref f, ref pn); 

     outgoing = (MSMQ.MSMQOutgoingQueueManagement)mgmt; 
     count = outgoing.MessageCount; 

    } 
    catch (Exception ee) 
    { 
     MessageBox.Show(ee.ToString()); 
    } 
    return count; 
} 

그것은 더 나은 출발점을 제공 할 수 있습니다.

0

많은 조합이있었습니다. 내가 PathName이 아닌 FormatName을 사용해야하는 가장 큰 이유.

_queueManager.Init("MyComputer", null, @"DIRECT=OS:MyComputer\PRIVATE$\MyQueue"); 

또한, 큐가 빈 상태 (empty)의 경우는 ... 예외가 발생합니다

는 COM 인터페이스를 사랑하고있어. :)

관련 문제