简体   繁体   English

如何使用MSMQ服务

[英]How to consume MSMQ service

I want to consume msmq service. 我想使用msmq服务。 But unable to send message to queue. 但是无法发送消息到队列。 Here is my code. 这是我的代码。

System.Messaging.MessageQueue msmQ = new System.Messaging.MessageQueue("net.msmq://myServerName/private/MyQueueName");

msg ="<nodeDetails><node>Node1</node></nodeDetails>";//Dummy value. it is XML structure consist of multiple node
 msmQ.Send(msg);

It give me error on msmQ.Send(msg) 它给我关于msmQ.Send(msg)的错误

error Message ="Length cannot be less than zero. Parameter name: length" 错误消息=“长度不能小于零。参数名称:长度”

Following things are install on my m/c 以下内容已安装在我的m / c上

  1. Microsoft Message Queue(MSMQ)Server Microsoft Message Queue(MSMQ)服务器
  2. Window Activation Process 窗口激活过程

Also when I tried as 当我尝试

 bool msmQExits = MessageQueue.Exists("net.msmq://myServerName/private/MyQueueName");

But it gives "Path syntax is invalid" 但是它给出“路径语法无效”

I am not able to get anything on it. 我什么都做不了。 What I have is just a msmq URL "net.msmq://myServerName/private/MyQueueName" 我只有一个msmq URL“ net.msmq:// myServerName / private / MyQueueName”

Please let me know how can I consume such url and Send my message to "MyQueueName" 请让我知道如何使用此类网址,并将消息发送到“ MyQueueName”

Any help is appreciated 任何帮助表示赞赏

Thanks in advanced. 提前致谢。

Change your queue name to this: 将您的队列名称更改为此:

var queueName = @"FormatName:DIRECT=HTTP://URLAddressSpecification/net.msmq://myServerName/private/MyQueueName";

And you cannot check if a remote query exists by MessageQueue.Exists method. 并且您无法通过MessageQueue.Exists方法检查是否存在远程查询。 It will always throw an exception. 它将始终引发异常。

You can check these links for more info: 您可以检查以下链接以获取更多信息:

Also, the problem is not with the message you see that length is less than 0. If you go deeper and check the stack trace you'll see that your queue name has an invalid format. 同样,问题不在于消息,您看到该长度小于0。如果您更深入并检查堆栈跟踪,您会发现队列名称格式无效。 It tries to find FORMAT occurrence inside your queue name, doesn't find it and Substring() method returns -1 there. 它尝试在队列名称中查找FORMAT出现的位置,但未找到它, Substring()方法在那里返回-1

Stacktrace: 堆栈跟踪:

   at System.String.Substring(Int32 startIndex, Int32 length)
   at System.Messaging.MessageQueue.ResolveFormatNameFromQueuePath(String queuePath, Boolean throwException)
   at System.Messaging.MessageQueue.get_FormatName()
   at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
   at System.Messaging.MessageQueue.Send(Object obj)
   at MessagingTest.Program.SendMessage(String str, Int32 x) in c:\Users\ivan.yurchenko\Documents\Visual Studio 2013\Projects\MSMQTestProjects\MessagingTest\MessagingTest\Program.cs:line 21
   at MessagingTest.Program.<Main>b__1() in c:\Users\ivan.yurchenko\Documents\Visual Studio 2013\Projects\MSMQTestProjects\MessagingTest\MessagingTest\Program.cs:line 38
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

Here is an example for how to consume the service. 这是有关如何使用服务的示例。

It has Wcf Service,Physical MSMQ, and the client project. 它具有Wcf服务,物理MSMQ和客户端项目。 So you have to have a WCF service to receive the message and msmq to store the message and a client to send the message. 因此,您必须具有WCF服务来接收消息,并且必须具有msmq来存储消息,并且必须具有客户端才能发送消息。

http://www.codeproject.com/Articles/326909/Creating-a-WCF-Service-with-MSMQ-Communication-and http://www.codeproject.com/Articles/326909/Creating-a-WCF-Service-with-MSMQ-Communication-and

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM