I don’t know the version of wV. My client only gave me the Broker, ClientId, Destination and the instrunctions to create a session with a CreateDurableSubscriber. I can create the connection, create the session, initialize the connection and start receiving messages. However i can’t read the body massage.
In the example below the msg is a BytesMessage, that i can’t extract the body message or convert to a string. Browsing the webMethods.Msg, i can’t found a way to obtain the message. BytesMessages are a type i cant convert into a string.
SAMPLE:
// get a destination
IDestination destination = isQueue ? MsgFactory.GetQueue(“SampleQueue”) : MsgFactory.GetTopic(props.DestinationName);
// get a connection factory
IConnectionFactory connectionFactory = MsgFactory.GetConnectionFactory(props.Broker, props.ClientID);
using (IConnection connection = connectionFactory.CreateConnection())
{
using (ISession session = connection.CreateSession(false, AcknowledgeMode.Auto))
{
using (IMessageConsumer consumer = session.CreateDurableSubscriber(destination, props.DestinationName))
{
// start the connection
connection.Start();
while (messageCount < messageTotal)
{
bodyMessage = "";
try
{
// receive a message
[b] IMessage msg = consumer.Receive();[/b]
if (msg is IMapMessage)
{
//Console.WriteLine("Message Body: " + ((ITextMessage)message).Text);
}
else if (msg is ITextMessage)
{
Console.WriteLine("Message Body: " + ((ITextMessage)msg).Text);
}
else if (msg is IBytesMessage)
{
//Console.WriteLine("Message Body: " + ((ITextMessage)message).Text);
}
}
catch (Exception ex)
{
//HelperLog.Logger.ErrorFormat("Error getting message from step. Message detail {0}", ex);
}
// increment the counter
messageCount++;
if (!string.IsNullOrEmpty(bodyMessage))
{
Process(bodyMessage);
}
}
} // close the consumer
} // close the session
} // close the connection
#broker#Universal-Messaging-Broker#Integration-Server-and-ESB#webMethods