in reply to CGI to MSMQ

I'd have to guess that you can only hit MSMQ using COM. If the Perl CGI is hosted on a Win32 box, you will likely want to use Win32::OLE to talk to the MSMQ. If you can describe how you would do it in VB or ASP, I can probably help translate.
HTH

Now, if you want to send a massage, they call me magic hands. ;)

mhoward - at - hattmoward.org

Replies are listed 'Best First'.
Re: Re: CGI to MSMQ
by Anonymous Monk on Jun 12, 2003 at 13:31 UTC
    Thanks hatt!

    I already have a .NET Web Service that sends the message, but my company doesn't use IIS (it is a Win32 box, through). The code in c# is like this (many apologies for posting non-Perl code on this site):

    [WebMethod] public void sendMessage(string messageText) { string queueName = @".\private$\myQueue"; MessageQueue myQueue = new MessageQueue(queueName); myQueue.Send(messageText); }

    Thanks again!
    Anonymous Monk

      Hmm, I don't seem to have a MessageQueue COM Object here, but here's my scratch at it:
      use Win32::OLE; my $myQueue = Win32::OLE->new("MessageQueue") or die("Create object failed! :P");
      This sets up the object for you. I don't see a way to pass args to the constructor, so you have to set the property for the target queue. Example:
      $myQueue->{targetQueue} = "./" . $private . "/myQueue";
      Then to send the message it will be so:
      $myQueue->Send($messageText);
      Note that these are analogs for what happens above, and you'll have to work it together like you want/need. I would have been more help if I had the MessageQueue object, but I'm sure my guesses are quite close.
      Also, I'm assuming you know a little about perl or can figure it from the code at hand; declaring variables, subs and such.

      hth

      Later that day: <mope> nobody ever comes back to tell if it worked :P </mope>

      mhoward - at - hattmoward.org
        Sorry for the late reply!

        Unfortunately, I get an error when creating the OLE object. Apparently the object name is wrong or there's no appropriate OLE object..

        Any ideas/advice/code appreciated!

        Anonymous Monk

        Sorry for the delayed response!

        Unfortunately, I get the error:
        Create object failed! :P

        I'm familiar with cgi and Perl, as well as MS technolgies, but using them together is still tricky..

        As usual, any ideas/code/suggestions welcome!
        Anonymous Monk.

      Seeing as you already have this C# Webservice why don't you call it from your Perl program using SOAP::Lite? You may need to add the SoapRpcMethod attribute to the above method under some circumstances.

      It is difficult to map the .NET System.Messaging stuff to Perl as it is a highly abstracted from the MSMQ API but there is an ActiveX interface that can be called using Win32::OLE. The following is unttested (this is a Linux Machine) but should give you a basic idea:

      use Win32::OLE; my $queueinfo = Win32::OLE->new('MSMQ.MSMQQueueInfo'); $queueinfo->{pathname} = '.\private$\myQueue'; my $queue = $queuinfo->Open(2,0); my $message = Win32::OLE->new('MSMQ.MSMQMessage'); $message->{Body} = 'Whatever'; $message->Send($queue);
      You might want to look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msmq/msmq_ref_app_81gz.asp for more on the MSMQ ActiveX interface.

      /J\
      
      Thanks both of you.

      My code so far is thus:

      use Win32::OLE; my $queueinfo = Win32::OLE->new('MSMQ.MSMQQueueInfo'); $queueinfo->{pathname} = '\\myServer\private$\myQueueName'; my $queue = $queueinfo->Open(2,0); my $myMsg = Win32::OLE->new("MSMQ.MSMQMessage") or die("Create message object failed! :P"); $myMsg->{Label} = 'myLabel'; $myMsg->{Body} = 'myBody'; $myMsg->Send($queue);

      The script doesn't die, but the message isn't delivered either. In the MS documentation, a MessageQueue object is returned from the $queueInfo->Open() call, but $myQueue of course isn't blessed in my script. Could this be part of the problem?

      Thanks again,
      A.M.