0

I want to consume msmq service. 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 gives me an error on msmQ.Send(msg)

Length cannot be less than zero. Parameter name: length

The following things are installed on my m/c:

  1. Microsoft Message Queue(MSMQ)Server
  2. Window Activation Process

Also when I tried as

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

it gives "Path syntax is invalid". I am not able to get anything on it.

I just have a msmq URL net.msmq://myServerName/private/MyQueueName.

How can I consume such URL and send my message to "MyQueueName"?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Sanket
  • 83
  • 7
  • Why are you trying to consume a net.msmq endpoint using system.messaging? You should be using a WCF client. – tom redfern Jul 08 '16 at 09:52
  • do you have any sample for that how to consume it using WCF client? I have one WCF service method which get call on particular action from front-end. with in which I have to call this msmq service. – Sanket Jul 08 '16 at 11:53

2 Answers2

0

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. 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. It tries to find FORMAT occurrence inside your queue name, doesn’t find it and Substring() method returns -1 there.

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()
Community
  • 1
  • 1
Ivan Yurchenko
  • 3,762
  • 1
  • 21
  • 35
0

Here is an example for how to consume the service.

It has Wcf Service,Physical MSMQ, and the client project. 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.

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

Ramesh
  • 1,692
  • 2
  • 18
  • 37