Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have finished a small Server and Client Solution using MSMQ for sending text messages between Server and Client.

Works perfect in my Domain.

Now I got the bad news. I must get it working without a domain (internet is available).

My solution is quite simple until now:

Checking and adding the queue:

public void check_Queue(string queueName)
{
    if (!MessageQueue.Exists(".\\" + queueName))
    {
        MessageQueue queue;
        //Prüfe und ggf. erzeuge MessageQueue
        try
        {
            queue = MessageQueue.Create(".\\" + queueName, false);
            //todo: Rechte prüfen und einschränken, Category ebenso, ID ggf auch
            queue.QueueName = queueName;
            queue.Label = queueName;

            //Rechte und Einstellungen MessageQueue
            // Erzeuge AccessControlList
            AccessControlList list = new AccessControlList();

            // Neuen Trustee erzeugen für alle Benutzer - todo später einschränken
            Trustee tr;
            if ((Thread.CurrentThread.CurrentUICulture.ToString().ToUpper() == "DE")
                || (Thread.CurrentThread.CurrentUICulture.ToString().ToUpper() == "DE-DE"))
                tr = new Trustee("Jeder"); //todo herausfinden wie man das generell hinbekommt
            else
                tr = new Trustee("Everyone");

            // AccessControlEntry erzeugen
            // dieser erlaubt Trustee vorerst alles
            AccessControlEntry entry = new AccessControlEntry(tr, GenericAccessRights.All, StandardAccessRights.All, AccessControlEntryType.Allow);
            // AccessControlEntry zur AccessControlList hinzufügen
            list.Add(entry);
            // AccessControlList für queue übernehmen
            queue.SetPermissions(list);
        }
        catch (Exception ex)
        {
            _log.Log.Error(SiCResourceManager.GetResourceString(SiCResourceManager.SiEStringResource.ErrorMessage) + Environment.NewLine + ex.Message.ToString());
        }
    }
}


Sending a message:

C#
public void SendMessage(string fullClientName, string msgText)
{
    try
    {
        // Die Message senden
        queue.Send(msgText);
        return;
    }
    catch (Exception ex)
    {
        _log.Log.Error(SiCResourceManager.GetResourceString(SiCResourceManager.SiEStringResource.ErrorMessage) + Environment.NewLine + ex.Message.ToString());
    }
}


Receiving a message:

public string ReceiveMessage(string queueName)
{
    // Formatter setzen
    queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });

    string msgText = "";
    try
    {
        // Message empfangen und formattieren, mit TimeOut
        TimeSpan maxTime = new TimeSpan(SiCGlobals.receiveTimeout);
        Message myMessage = queue.Receive(maxTime);
        msgText = (string)myMessage.Body;
    }

    catch (MessageQueueException ex)
    {
        // Fehler beim Empfang oder in Queue
    }

    // Serialisierungs-Fehler
    catch (InvalidOperationException ex)
    {

    }

    // unbekannter Fehler
    catch (Exception ex)
    {

    }
    //Meldung zurückgeben
    return msgText;
}


It seems I already get a problem when I try to check / add my queue and I am not in a domain.

Anybody experienced with that and could please give me some hints?

Thanks a lot

Eric

PS:

XML
I now startet my server application on a PC which is not in the domain.

Checking the Queue seems to work.

But then I get an exception here "Workstation installation does not support..."
when starting it in the domain it worked.

<pre> lang="cs">queue.ReceiveCompleted += new
    ReceiveCompletedEventHandler(QueueReceiveCompleted);</pre>




PPS: I changed all the queues to be private queues. Adding the queue works,
and the Receive..Handler does not throw an exception anymore.

But (Firewall is off) the Server does not take any messages.

When sending a message with the Client I now use:
MessageQueue clientQueue = new MessageQueue(fullName + @"\Private$\" + queueName);

I get an "Invalid queue path name". fullName is an IP right now.
When I remove that Private$\\ then path is not invalid anymore, but it does not find that queue (because it is provate now). Any suggestion how to send a message to that private queue? Thanks!
Posted
Updated 7-Sep-11 5:53am
v3

1 solution

FormatName:DIRECT=TCP:


Seems to work when I put this before the fullname
when sending a message to the server (which is not in the domain).
Vodoo Stuff :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900