|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
Setting the message id in a VB.NET application |
« View previous topic :: View next topic » |
Author |
Message
|
jefflowrey |
Posted: Fri Jun 24, 2005 3:16 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
PeterPotkay wrote: |
Still wonder if Unicode is so great, why isn't everything using it? Or is that the direction apps are slowly going to? WB-IMB uses Unicode internally, correct? UTF-8, or UTF16? |
It's the direction everything is going, but slowly. WBIMB does use unicode "internally", and I forget which one. I'm sure the manuals say ...  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
jigjim |
Posted: Wed Jun 29, 2005 12:35 pm Post subject: |
|
|
Apprentice
Joined: 30 Mar 2004 Posts: 41
|
Hi,
I do the setting of message ID the follwoing way in my code.
Code: |
msg = new MQMessage();
msg.MessageType = MQC.MQMT_REQUEST;
msg.Format = MQC.MQFMT_IMS_VAR_STRING;
msg.Persistence = MQC.MQPER_NOT_PERSISTENT;
msg.Encoding = 17;
msg.CharacterSet = 37;
Random rnd = new Random();
Byte[] b = new Byte[10];
rnd.NextBytes(b);
msg.MessageId = b;
msg.ReplyToQueueName = replyQ;
MQPutMessageOptions pmo = new MQPutMessageOptions();
string data = "CMDMASK " + cmd;
short LL = (short)(data.Length + 4);
short ZZ =0;
byte[] tab= new byte[2];
tab[0]=(byte)((LL&0xFF00)>>8);
tab[0+1]=(byte)(LL&0x00FF);
// Build the IMS Meesage
msg.WriteBytes(tab);
msg.WriteInt16(ZZ);
msg.WriteString(data);
q.Put(msg, pmo);
q.Close();
mgr.Disconnect();
retMsg = getIMS(b);
|
The Return Message is picked up as:
Code: |
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.Options = MQC.MQGMO_WAIT;
gmo.WaitInterval = 10;
qmsg = new MQMessage();
qmsg.CorrelationId = id; // Where id = b "getIMS(b)" from the Put method
q.Get(qmsg, gmo);
retMsg = qmsg.ReadString(qmsg.MessageLength);
|
For my .NET application (running from Windows box as a batch process, windows service the above code works fine.
But die to some recent enhancements needed, I tried to use this code in my ASP.NET Web App. I have the following problems:
1. The user id it picks us by default is ASPNET. need to know how can we override it.
2. The Message ID shows up as garbled in the Co-Relation ID field of the reply message. Due to this it is unable to pick the Reply message from the Q and throws a 2033.
Can somebody help me in:
1. Fix the above errors ?
2. How to collect the Message ID (automatically populated by the API) after the PUT is done. I can then set this as Co Relation id of my reply message and read the message from the Reply Q
Thanks
Jigs |
|
Back to top |
|
 |
JohnGee |
Posted: Tue Jul 12, 2005 8:23 am Post subject: |
|
|
Newbie
Joined: 07 Apr 2005 Posts: 8
|
Here is something I've found that can convert the message & correlation id byte arrays to string and then back to byte arrays without any ASCII conversion issues:
Imports Microsoft.VisualBasic '--for AscW function
Private Function byte2String(ByVal input() As Byte) As String
Dim charHelper(23) As Char
Dim returnStr As String
'--copy the byte array to the char array
input.CopyTo(charHelper, 0)
'--put the char array to the string
For Each singleton As Char In charHelper
returnStr = returnStr + singleton.ToString
Next
Return returnStr
End Function
Private Function string2Byte(ByVal input As String) As Byte()
Dim charHelper(23) As Char
Dim byteArray(23) As Byte
'--copy the string into the char array
charHelper = input.ToCharArray
'--copy the char array to the byte array
For idx As Integer = 0 To 23
byteArray(idx) = AscW(charHelper(idx))
Next
Return byteArray
End Function |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jul 12, 2005 1:32 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Make sure you do not expect a String representation of the byte array:
like "this is my byte array"
There are a few fundamentals about byte arrays.
There is no indication as to what char representation is acceptable for a byte value outside of char values.
Ex in C hex 00 will terminate the string....
The only way to correctly represent a byte array is to display the hex value of each byte:
Assuming that your platform is ascii:
String "01" ==> byte array ==> hex representation "0x3031"
Enjoy  |
|
Back to top |
|
 |
klamerus |
Posted: Sat Jul 16, 2005 5:32 pm Post subject: |
|
|
 Disciple
Joined: 05 Jul 2004 Posts: 199 Location: Detroit, MI
|
Well UNICODE is pretty darn useful, but you're asking a question about a product from a company that still calls hard drives DASD; believes that EBCDIC is the answer to everything; and thinks that a good way to specify a server to the MQ API is via an environment variable.
Ours is not to wonder way...except in open forums like this  |
|
Back to top |
|
 |
|
|
|
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
|
|
|
|