ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » Access MQ Queues from ASP.NET APPLICATION

Post new topic  Reply to topic
 Access MQ Queues from ASP.NET APPLICATION « View previous topic :: View next topic » 
Author Message
nandu
PostPosted: Thu Feb 10, 2005 9:54 am    Post subject: Access MQ Queues from ASP.NET APPLICATION Reply with quote

Newbie

Joined: 09 Feb 2005
Posts: 9

I am using following code to access mq queue manager and queues from asp.net application . But through windows application I am able to acces these queues but from web application i am not able to access queue Manager . Any inputs

Imports IBM.WMQAX
Imports IBM.WMQ.MQC

Public Class m51633
Inherits System.Web.UI.Page
Public mqenv As IBM.WMQ.MQEnvironment
Public mqenv1 As IBM.WMQ.MQEnvironment
Dim strError_code As String
Dim strErrorMessage As String
Dim mqSession As MQSession '* MQSession instance
Dim mqQMgr As MQQueueManager '* MQQueueManager instance
Dim mqQueue As MQQueue '* MQQueue instance
Dim ObjMqMsg As MQMessage '* MQMessage instance
Dim ObjMsgOptsGet As MQGetMessageOptions
Dim ObjMsgOpts As MQPutMessageOptions '* MQPutMessageOptions instance
Dim qmgrName As String '* Name of queue manager to use
Dim Put_Queue_Name As String '* Name of queue to use
Dim Get_Queue_Name As String
Dim Put_message As String '* Message to put
Dim isContinue As Boolean = True '* Whether to continue processing
Dim strparm As String
Dim strresult As String
Dim MessageId As Byte()
Dim mqMsg1 As MQMessage
Dim mqGetMsgOpts As MQGetMessageOptions
Dim strCorrID As String
Dim strmessId As String
Dim corr_encode As New System.Text.UTF8Encoding
Dim corr_id As Byte()
Dim mess_encode As New System.Text.UTF8Encoding
Dim mess_id As Byte()
Dim strprinter As String
Dim partnum As String
Dim strinsp As String
Dim Qty As Long
Dim userid As String
Dim strlineno As String


#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents btn_Submit As System.Web.UI.WebControls.Button
Protected WithEvents txt_clockno As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_prntcrntdate As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_crtfrmload As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_lineno As System.Web.UI.WebControls.TextBox
Protected WithEvents btn_reset As System.Web.UI.WebControls.Button
Protected WithEvents txt_lpw As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_psl As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_noofcopies As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno1 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno1 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces1 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno2 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno2 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces2 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces3 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces4 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces5 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces6 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces7 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces8 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces9 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces10 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces11 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno3 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno4 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno5 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces12 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces13 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces14 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces15 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno6 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno7 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno8 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno9 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno10 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno11 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno12 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno13 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno14 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno15 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno3 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno4 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno5 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno6 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno7 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno8 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno9 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno10 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno11 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno12 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno13 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno14 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno15 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno16 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno17 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno18 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno19 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno20 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno21 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno22 As System.Web.UI.WebControls.TextBox
Protected WithEvents Textbox23 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno24 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno25 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno26 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno27 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno28 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno29 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_inspno30 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno16 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno17 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno18 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno19 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno20 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno21 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno22 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno23 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno24 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno25 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno26 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno27 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno28 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno30 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_partno29 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces16 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces17 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces18 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces19 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces20 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces21 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces22 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces23 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces24 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces25 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces26 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces27 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces28 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces29 As System.Web.UI.WebControls.TextBox
Protected WithEvents txt_pieces30 As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here
End Sub
#Region "Event Handlers"
Private Sub btn_Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Submit.Click
'Dim strmq As String
'Dim objMq As New MQSeries.MQfunctions.MQfunctions
'strmq = objMq.LPWSPrint(txt_partno1.Text, txt_inspno1.Text, Convert.ToInt16(txt_pieces1.Text))


strparm = "BON5PC5 LM11949 200241 dutka 1 2005/02/03"
'strparm = "BON5PC5 LM11949 200241 sivan1 2005/02/03"
'name1 = System.Environment.UserName()
'envname = System.Environment.GetEnvironmentVariables().Item("MQSERVER")
'name1 = System.Environment.UserDomainName()

set_MQ_Parms_LPW()
If PutMessage(strparm) = True Then
If GetMessage() = True Then
End If
End If
End Sub
Private Function fnUIDGenerate() As String
Dim OldDate As Date, NewDate As Date
Dim dblTemp As Double
OldDate = Now() 'get current datetime
Do While 1 = 1 'loop until datetime changes
NewDate = Now()
If OldDate <> NewDate Then
Exit Do
End If
Loop
dblTemp = System.DateTime.Now.ToOADate()
fnUIDGenerate = Strings.Left(CStr(dblTemp * 10000000), 12) 'convert to 12 char string
End Function

Public Function WaitInterval(ByVal inWaitInterval As Integer) As Long
If CDbl(inWaitInterval) <= 0 Then 'set default value if invalid
WaitInterval = 10000 '10 seconds
Else
WaitInterval = CLng(inWaitInterval) * 1000
End If
End Function
Public Function PutMessage(ByVal strparm As String) As Boolean

PutMessage = False
Dim Put_queue As String
strCorrID = fnUIDGenerate()
'strmessId = fnUIDGenerate()
corr_id = corr_encode.GetBytes(strCorrID)
mess_id = mess_encode.GetBytes(Space(2))
If Put_Queue_Name = "" Then
strErrorMessage = "Send queue name must be specified."
Exit Function
End If
Try
Dim envname As String

mqQMgr = mqSession.AccessQueueManager(qmgrName)
If mqSession.CompletionCode = MQCC_OK Then
Put_queue = Put_Queue_Name
mqQueue = mqQMgr.AccessQueue(Put_queue, MQOO_OUTPUT + MQOO_FAIL_IF_QUIESCING + MQOO_INQUIRE)
If mqSession.CompletionCode = MQCC_OK Then
ObjMqMsg = mqSession.AccessMessage()
ObjMsgOpts = mqSession.AccessPutMessageOptions()
ObjMqMsg.WriteString(strparm)
ObjMqMsg.CharacterSet = 437
'ObjMqMsg.Version = MQMD_VERSION_2
ObjMqMsg.Format = MQFMT_STRING
ObjMqMsg.Expiry = MQEI_UNLIMITED
ObjMqMsg.ReplyToQueueManagerName = qmgrName
ObjMqMsg.ReplyToQueueName = Get_Queue_Name
ObjMqMsg.CorrelationId = corr_id
mqQueue.Put(ObjMqMsg, ObjMsgOpts)
If mqSession.CompletionCode = MQCC_OK Then
mqQMgr.Commit()
PutMessage = True
Else
strErrorMessage = "Put failed. Completion: " & mqSession.CompletionCode & " Reason: " & mqSession.ReasonCode & " " & mqSession.ReasonName
End If
Else
strErrorMessage = "AccessQueue failed. Completion: " & mqSession.CompletionCode & " Reason: " & mqSession.ReasonCode & " " & mqSession.ReasonName
End If

mqQueue.Close()
ObjMqMsg = Nothing
ObjMsgOpts = Nothing
mqQueue = Nothing
Else
strErrorMessage = "AccessQueueManager failed. Completion: " & mqSession.CompletionCode & " Reason: " & mqSession.ReasonCode & " " & mqSession.ReasonName
End If
Catch ex As Exception
'Debug.WriteLine(ex.Message)
End Try


End Function
Public Function set_MQ_Parms()
qmgrName = "ctnhmq01.mqst"
Put_Queue_Name = "TMKN.REUSE.SUBROUTINE"
Get_Queue_Name = "TMKN.REUSE.SUBROUTINE.REPLY"
Put_message = strparm
mqSession = New MQSession
mqenv.Hostname = "ctnhmqt"
mqenv.Channel = "CTNHMQ01"
mqenv.Port = 1414
End Function
Public Function set_MQ_Parms_LPW()
qmgrName = "ctnhmq02.mqst"
Put_Queue_Name = "LPWS.PRINT.LPW"
Get_Queue_Name = "LPWS.PRINT.LPW.REPLY"
Put_message = strparm
mqSession = New MQSession
mqenv.Hostname = "ctnhmqt"
mqenv.Channel = "CTNHMQ02"
mqenv.Port = 1416
End Function
Public Function GetMessage() As Boolean

GetMessage = False
Dim Get_Queue As String
If Get_Queue_Name = "" Then
strErrorMessage = "Reply queue name must be specified."
Exit Function
End If
Try
If mqQMgr Is Nothing Then
mqQMgr = mqSession.AccessQueueManager(qmgrName)
End If

If mqSession.CompletionCode = MQCC_OK Then
Get_Queue = Get_Queue_Name
mqQueue = mqQMgr.AccessQueue(Get_Queue, MQOO_INPUT_SHARED + MQOO_INQUIRE)
If mqSession.CompletionCode = MQCC_OK Then
ObjMqMsg = mqSession.AccessMessage()
ObjMsgOptsGet = mqSession.AccessGetMessageOptions()
'ObjMqMsg.CorrelationId = corr_id
'ObjMqMsg.MessageId = mess_id
'ObjMqMsg.MessageData = strparm
'ObjMsgOptsGet.MatchOptions = 2
ObjMsgOptsGet.Options = MQPMO_SYNCPOINT
ObjMsgOptsGet.WaitInterval = 15000
mqQueue.Get(ObjMqMsg, ObjMsgOptsGet)
If mqSession.CompletionCode = MQCC_OK Then
mqQMgr.Commit()
strresult = ObjMqMsg.MessageData
corr_id = ObjMqMsg.CorrelationId
'mess_id = ObjMqMsg.MessageId
GetMessage = True
Else
strErrorMessage = "Get failed. Completion: " & mqSession.CompletionCode & " Reason: " & mqSession.ReasonCode & " " & mqSession.ReasonName
End If
Else
strErrorMessage = "AccessQueue failed. Completion: " & mqSession.CompletionCode & " Reason: " & mqSession.ReasonCode & " " & mqSession.ReasonName
End If
mqQueue.Close()
ObjMqMsg = Nothing
ObjMsgOptsGet = Nothing
mqQueue = Nothing
Else
strErrorMessage = "AccessQueueManager failed. Completion: " & mqSession.CompletionCode & " Reason: " & mqSession.ReasonCode & " " & mqSession.ReasonName
End If
Catch mqe As IBM.WMQ.MQException
'* stop if failed
strresult = "create of MQQueueManager ended with " + mqe.Message()
'PartNo.Text = strresult
isContinue = False
End Try
End Function

Private Sub btn_reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_reset.Click

End Sub
#End Region
End Class
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Feb 10, 2005 10:03 am    Post subject: Re: Access MQ Queues from ASP.NET APPLICATION Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

nandu wrote:
from web application i am not able to access queue Manager .

How do you know? What errors do you get?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
nandu
PostPosted: Thu Feb 10, 2005 10:35 am    Post subject: Reply with quote

Newbie

Joined: 09 Feb 2005
Posts: 9

I am getting 2035 error - Access not authorized error but if i try the same code from windows application I am able to access the queue manager
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Feb 10, 2005 10:39 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

nandu wrote:
I am getting 2035 error - Access not authorized error but if i try the same code from windows application I am able to access the queue manager


And is the user that is running the web code authorized for the queue manager?

Do you know what user that is?

Have you looked for other similar questions, that might tell you what to do?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
nandu
PostPosted: Thu Feb 10, 2005 10:45 am    Post subject: Reply with quote

Newbie

Joined: 09 Feb 2005
Posts: 9

Thats the portion I am confused .

For windos application i am able to run this code properly through my userid . i am not explicitly setting anything

so web how should I set the userid . I belive it will take the winNt userid and check rite . Please confirm.

I checked this form but still not able to get much .
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Feb 10, 2005 2:31 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

You will need to access MQ from the Web through a DCom/DCom+ object which will allow you to set the user to be used to access MQ.

Enjoy
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Thu Feb 10, 2005 3:19 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

fjb_saper wrote:
You will need to access MQ from the Web through a DCom/DCom+ object which will allow you to set the user to be used to access MQ.

Enjoy


Or simply grant permissions to the user that is running the web code.

Which is very much dependent on the web server in question. I'd guess, since this is .NET, it is likely IIS. In which case it is very much dependent on the security settings of the server, the site and the app.

So nandu should ask his web administrator.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
swood
PostPosted: Thu Feb 10, 2005 7:13 pm    Post subject: Reply with quote

Novice

Joined: 10 Dec 2004
Posts: 20

If you are using forms authentication in your web app then you are running under the ASP.NET Machine Account(ASPNET). You need an administrator account to connect to the MQ Server and it must match one on the MQ Server itself. You could use impersonation in the web.config and impersonate an account that is in the administrators group on your machine. This is very risky to run a web app under an administrators account though. You could possibly try a web service that does the work for you and authenticate against it with an NT principal that you create. I believe the Web service will then run under your authenticated user account. A little better but again may be risky. Making your component run in COM+ and access it through the web app sounds a lot more secure and if you need to scale this up later I suppose the COM+ server component could be moved to another computer. This would be my choice although COM+ is not my thing, the secure access would be worth it.
_________________
I don't know as much as I wish I did.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
jefflowrey
PostPosted: Fri Feb 11, 2005 4:54 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

swood wrote:
You need an administrator account to connect to the MQ Server


I don't think so, unless that's a .NET limitation.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
swood
PostPosted: Fri Feb 11, 2005 5:40 am    Post subject: Reply with quote

Novice

Joined: 10 Dec 2004
Posts: 20

Thanks for pointing that out jefflowrey...that changes things a lot.

It appears that I have been lazy and didn't test something I read. I have changed the login account on my test server to be in the users group and changed the client computer's account to be in the users group and it works fine from a windows box to a windows box.
Sorry for the misinfo in the previous post.
_________________
I don't know as much as I wish I did.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
nandu
PostPosted: Fri Feb 11, 2005 6:45 am    Post subject: Got access Reply with quote

Newbie

Joined: 09 Feb 2005
Posts: 9

Finally I was able to get access the MQ sever .

i changed the username and password in machine.config to my windows nt and password and was able to run the application successfully.

Thank you everyone for the support
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » Access MQ Queues from ASP.NET APPLICATION
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.