3

For my internship i'm making an application which sends messages using MSMQ. Everything works fine currently except the encryption. (Private data)

The application sends a list of a custom object to the server, and retrieves it from the server. But when I use: message.UseEncryption = true; the unittest won't run.

My code:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace MSMQClient
{
    public class ClientManager
    {
        public bool connected { get; private set; }
        public string queueLocation { get; private set; }

        public Message message { get; private set; }
        public MessageQueue messageQueue { get; private set; }
        public List<DataContracts.MemoryTransaction> notSentTransactions { get; private set; }

        public ClientManager()
        {
            queueLocation = @".\private$\testqueue";

            if (MessageQueue.Exists(queueLocation))
            {
                MessageQueue.Delete(queueLocation);
            }

            messageQueue = MessageQueue.Create(queueLocation);
            //messageQueue.EncryptionRequired = EncryptionRequired.Body;
        }

        public bool isConnected()
        {
            if (messageQueue != null)
            {
                return true;
            }
            return false;
        }

        public bool sendToServer(List<DataContracts.MemoryTransaction> memoryTransactions)
        {
            try
            {
                message = new Message();

                message.Formatter = new XmlMessageFormatter(new Type[] { typeof(List<DataContracts.MemoryTransaction>) });

                //message.UseEncryption = true;

                message.Body = memoryTransactions;
                message.Label = "MemoryTransList";
                message.Priority = MessagePriority.Normal;

                messageQueue.Send(message);
                return true;
            }
            catch (Exception ex)
            {
                Cocosoft.SDK.Logging.TextLogging(ex.ToString());

                notSentTransactions = memoryTransactions;

                return false;
            }
        }
    }

I found this site and tried a lot, but I can't get it working... I think I have to use the next things:

public bool sendToServer(List<DataContracts.MemoryTransaction> memoryTransactions)
{
    try
    {
        message = new Message();
        message.Body = ... //memoryTransactions
        message.Label = ... //"MemoryTransList"
        message.Priority = ... //Priority.Normal
        message.Formatter = ... //new XmlMessageFormatter(new Type[] { typeof(List<DataContracts.MemoryTransaction>) });
        message.UseEncryption = ... //true
        message.ConnectorType = ... //???
        message.EncryptionAlgorithm = ... //EncryptionAlgorithm.Rc2
        message.DestinationSymmetricKey = ...//???

        messageQueue.Send(message);
        return true;
    }
    catch (Exception ex)
    {
        notSentTransactions = memoryTransactions;
        return false;
    }
}

Who can help me? Am I missing something?

But the Cocosoft SDK saves this in a logging.txt:

Translation: The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted.

System.Messaging.MessageQueueException (0x80004005): De opgegeven indelingsnaam ondersteunt de gevraagde bewerking niet. Een directe wachtrij-indelingsnaam kan bijvoorbeeld niet worden verwijderd.
   bij System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
   bij System.Messaging.MessageQueue.Send(Object obj)
   bij MSMQClient.ClientManager.sendToServer(List`1 memoryTransactions) in d:\StageGeert\UnitTestStage\MSMQClient\ClientManager.cs:regel 96
Geert Berkers
  • 452
  • 4
  • 14
  • Translating the error message gives "There are insufficient resources are available to perform the operation.". That doesn't seem related to encryption. Take a look at this: https://support.microsoft.com/en-us/kb/899613 – Rob Oct 22 '15 at 08:34
  • Also this: http://stackoverflow.com/questions/1732515/msmq-what-can-cause-a-insufficient-resources-to-perform-operation-error-when – Rob Oct 22 '15 at 08:41
  • Hmm, But it works when I don't use the encription. Anyway, thank you for your help! – Geert Berkers Oct 22 '15 at 08:42
  • It's *possible* that the encryption is causing the packets to be too large to send to the server. I don't know much about MSMQ, but to me it seems like the error is not caused by encryption, but the encryption is triggering some other issue. Are you able to send a small message with encryption, just to test? Or a extra-large, non-encrypted message? – Rob Oct 22 '15 at 08:47
  • Yes, I have a list with 500 items which works without encryption. But also when I use 10 items in the list, or even 1, it fails :( – Geert Berkers Oct 22 '15 at 08:49
  • Even when I use a string in stead of a list it won't finish and gaves me the last error. So I think I need to set more properties, but I don't get which one... – Geert Berkers Oct 22 '15 at 09:03
  • With your new error, take a look here: http://stackoverflow.com/a/20049331/563532 and https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/ca7d2c1b-2272-4b5f-b402-b64d6f2ac8c6/msmq-systemexception-fatal-error-cannot-store-content-to-the-message-queue?forum=msmq – Rob Oct 22 '15 at 10:02
  • Most discussions I've found seem to revolve around the formatname - so you might want to look into that. How it's related to encryption, I have no idea. Sorry I can't help out more, I'm not well versed at all with MSMQ but hopefully this gives you a clue – Rob Oct 22 '15 at 10:03
  • Also http://stackoverflow.com/questions/23669683/msmq-complaining-about-format-name-while-reading-messages – Rob Oct 22 '15 at 10:04
  • Thank you! I will look into it after my break – Geert Berkers Oct 22 '15 at 10:10

3 Answers3

1

I found a solution! I was using a local version of MSMQ. But I had to implement in in Azure, so I used Azure Service Bus. This was a bit different then local message queuing. But thanks to the Azure Service Bus, the problem is solved! Good Job Microsoft!

Geert Berkers
  • 452
  • 4
  • 14
0

If you set up message.UseEncryption = true; the Privacy Level of a target queue must be "Body" or "Optional". If privacy level of a target queue is "None" - it will reject encrypted messages. https://msdn.microsoft.com/ru-ru/library/ms700286(v=vs.85).aspx

-1

There is a checkbox in the computer management console for MSMQ that sets a message storage limit. Perhaps the encryption is forcing the messages to exceed this storage limit. Can you try to uncheck the storage limits checkboxes to see if that allows you to properly send the messages?