| By Stanimir Stanev, Rob Bartlett | Article Rating: |
|
| March 3, 2008 06:00 AM EST | Reads: |
14,235 |
Next, we attach the SOAP as a byte array to a message and send it to the queue/topic.
IBytesMessage message = session.CreateBytesMessage();
message.Content = bytBody;
//Give the address of our temporary queue
// so the service knows where to send the response
message.NMSReplyTo = queue;
using (IMessageProducer producer = session.CreateProducer())
{ NmsDestinationAccessor destinationResolver = new NmsDestinationAccessor();
IDestination destination = destinationResolver.ResolveDestinationName(session, _queueName);
producer.Send(destination, message);
}
Now we wait for a response. We set a timeout (as a TimeSpan). Here it's a fixed value of 10 seconds for illustration, but it could easily come from a config file or passed as a property in the ActiveMqWebRequestCreate.
IBytesMessage response = (IBytesMessage)
consumer.Receive(
TimeSpan.FromSeconds(10))
as IBytesMessage;
stream = new MemoryStream();
stream.Write(response.Content, 0, response.Content.Length);
} } }
catch (NMSException e)
{ throw (e); }
finally
{ m_RequestStream.InternalClose(); }
ActiveMqQueueWebResponse resp = new ActiveMqQueueWebResponse();
Here we set the stream to our own.
resp.SetDownloadStream(stream);
return resp;
}
Our ActiveMqWebResponse class inherits System.Net.WebResponse and does little more than provide a setter and override the getter on the response stream, since the stream in the built-in WebResponse is read-only.
public class ActiveMqQueueWebResponse : WebResponse
{
private Stream m_ResponseStream;
private long m_lngContentLength;
...
internal void SetDownloadStream(Stream vobjResponseStream)
{ m_ResponseStream = vobjResponseStream;
m_ResponseStream.Position = 0; // Rewind the stream
m_lngContentLength = m_ResponseStream.Length;
}
public override Stream GetResponseStream()
{ return m_ResponseStream;
} }
ActiveMqWebRequestCreate
ActiveMqWebRequestCreate
is a class that is used to create instances of our objects instead of
the built-in ones for a particular URI prefix. We'll see how this is
used in the client application.
public class ActiveMqQueueWebRequestCreate : IWebRequestCreate
{
This has the same properties that are on the ActiveMqWebRequest so it can set them when it instantiates the requests.
...
public WebRequest Create(System.Uri uri)
{ ActiveMqQueueWebRequest request = new ActiveMqQueueWebRequest(
uri, _queueAddress, _queueName, _username, _password);
return request;
} }
Published March 3, 2008 Reads 14,235
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Stanimir Stanev
Stanimir Stanev is a senior consultant at MomentumSI's Enterprise Architecture Solutions practice. He has many years of experience focusing on providing enterprise architecture and strategy expertise to companies looking to migrate to or maximize the advantages of SOA principles.
More Stories By Rob Bartlett
Rob Bartlett is a senior consultant at MomentumSI's Software Development Solutions practice. He has over a decade of experience in technical roles, guiding major corporations in the design, implementation, and integration of business solutions.
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?








































