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