Author |
Message
|
kun.leeing |
Posted: Fri Dec 26, 2008 7:56 am Post subject: XMS How to create QueueBrowser using C# |
|
|
 Disciple
Joined: 27 Sep 2008 Posts: 171
|
hi, experts. there's a problem about queue browser using C# with XMS.
whatever replace '??' with 'IMessage' or other type, it throws an error 'unable to cast object of type... to type ...'.
Code here
Code: |
IDestination iDest;
iDest = session.CreateQueue("TEMP.LQUEUE");
IQueueBrowser queue_browser = session.CreateBrowser(iDest);
connection.Start();
IEnumerator<??> iterator_msg = (IEnumerator<??>)queue_browser.GetEnumerator();
while(){
...
}
|
No samples can be found in src folder of ia9h,could anybody give an demostration about browsing mesage from a queue ? |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Dec 26, 2008 11:34 am Post subject: Re: XMS How to create QueueBrowser using C# |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
kun.leeing wrote: |
hi, experts. there's a problem about queue browser using C# with XMS.
whatever replace '??' with 'IMessage' or other type, it throws an error 'unable to cast object of type... to type ...'.
Code here
Code: |
IDestination iDest;
iDest = session.CreateQueue("TEMP.LQUEUE");
IQueueBrowser queue_browser = session.CreateBrowser(iDest);
connection.Start();
IEnumerator<??> iterator_msg = (IEnumerator<??>)queue_browser.GetEnumerator();
while(){
...
}
|
No samples can be found in src folder of ia9h,could anybody give an demostration about browsing mesage from a queue ? |
Depending on the java version (an I am aware that we are talking c# XMS here) the enumerator is not necessarily typed.
Anyways what you are accessing in your code is an enumerator. so the code would look something like this:
Code: |
IEnumerator myenum = (IEnumerator) queue_browser.getEnumerator();
IMessage mymess = null;
While(myenum.hasNext()){
mymess = (IMessage) myenum.nextElement();
} //endwhile |
This is a poor exemple as I am way more fluent in java than in c# but you should get the drift.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kun.leeing |
Posted: Fri Dec 26, 2008 5:42 pm Post subject: |
|
|
 Disciple
Joined: 27 Sep 2008 Posts: 171
|
Thanks for your help,saper.
But it seems that it does not work in c#.
There's only a generic type of IEnumerator and can not be converted to IMessage. |
|
Back to top |
|
 |
mqjeff |
Posted: Sat Dec 27, 2008 7:41 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
What version of .NET are you trying to use? Are you trying to use a supported version for XMS? Are you sure you are required to specify a generic for the IEnumerator?
It's not as clear from your post if you're having issues using the iterator, or just declaring the generic. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Dec 27, 2008 11:22 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
kun.leeing wrote: |
Thanks for your help,saper.
But it seems that it does not work in c#.
There's only a generic type of IEnumerator and can not be converted to IMessage. |
Excuse me for still not getting it.
An Enumerator interface IEnumerator is as far as I remember a POINTER to the data and as such has no other type.
You want to cast the result of IEnumerator.getNext() to IMessage and not the IEnumerator! .
Trying to cast the IEnumerator to IMessage should get you a ClassCastException at runtime.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|