| By Stanimir Stanev, Rob Bartlett | Article Rating: |
|
| March 29, 2008 04:00 PM EDT | Reads: |
14,516 |
.NET SOAP over JMS
Boiled down, this JMS
solution hijacks the SOAP request before it goes over the wire, sends
it over JMS, listens for a response via JMS then returns the SOAP
response back to the caller, allowing it to finish processing. We only
pass the SOAP through the system - we don't have to do anything special
to generate it, process it, serialize it, or deserialize it. We let
.NET do the heavy lifting that it was going to do anyway.
Normally, a Web Service will use an HTTP URI. When the Web Service proxy makes http calls, it causes the WebRequest.Create() method to produce an instance of HttpWebRequest. The proxy generates the SOAP, hands it off to the HttpWebRequest, which sends it over the wire, gets a response, and then sends that to the HttpWebResponse. Finally, the proxy takes over again. (See Figure 2)
We're going to take advantage of the "pluggable protocol" feature in .NET to make using JMS almost transparent. We say "almost" because we don't want to supersede HTTP in all cases - just for certain services. First, we'll need to know what flavor of JMS we're using. For this article, we're focusing on ActiveMQ because it's freely available and already has a pure .NET API. The .NET API we use is from Spring.NET. There are other options, such as OpenMQ and Tibco. Even if there were no .NET APIs already, we could wrap a dll. If the API existed only in Java, there are technologies such as JNBridge that can bridge technologies.
Once the JMS API is selected, we need to create several components: an ActiveMqWebResponse, an ActiveMqWebRequest, an ActiveMqWebRequestCreate, and an ActiveMqSoapStream - a specialized stream for hijacking the SOAP. These classes are custom versions of the components used in the normal flow of HTTP Web Services. Then, of course, we need a consumer.
ActiveMqSoapStream
The specialized stream
is where we do the fancy footwork to hijack the SOAP. We don't want the
proxy to realize it's dealing with a special stream. This class
inherits System.IO.Stream and is mostly a pass-through to an
encapsulated stream. The primary difference is that it overrides the
Close() method called by the base WebRequest. Instead of closing the
stream, this method rewinds the inner stream so our hijacking code can
process the stream from the beginning. It also has an internal close
method that our ActiveMqWebRequest will call to truly close the
underlying stream when it's done with it, otherwise the stream would
stay open indefinitely.
public class ActiveMqSoapStream : Stream
{
private Stream m_Stream;
public override void Close()
{ m_Stream.Position = 0;}
internal void InternalClose()
{ if (this.CanSeek == true) m_Stream.Close();}
}
ActiveMqWebRequest
The ActiveMqWebRequest
is where the bulk of the work happens. It inherits from
System.NET.WebRequest and implements the abstract methods and
properties. There are a few custom properties for JMS-specific
information such as the address, username, password, and queue name. We
also have a field of type ActiveMqSoapStream.
public class ActiveMqQueueWebRequest : WebRequest
{
protected ActiveMqSoapStream m_RequestStream;
private string _password;
private string _username;
private string _queueAddress;
private string _queueName;
...
For brevity's sake, I won't go into the details of the property accessors or pass-through methods. The methods we're most interested in are GetRequestStream() and Get-Response(). GetRequestStream() is where we replace the default stream with our own.
public override Stream GetRequestStream()
{
m_RequestStream = new ActiveMqSoapStream(new MemoryStream(),
true, true, true);
return m_RequestStream;
}
GetResponse() is where we send the request, listen for a response, and then put the response in a return stream. This is the workhorse of the class. The first thing we do is access the SOAP stream as an array of bytes.
public override WebResponse GetResponse()
{
byte[] bytBody = new Byte[m_RequestStream.Length];
m_RequestStream.Read(bytBody, 0, bytBody.Length);
Published March 29, 2008 Reads 14,516
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.
![]() |
sjsu 04/23/08 07:52:59 PM EDT | |||
good job man....... really good idea |
||||
- The Top 150 Players in Cloud Computing
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- Industry Experts Discuss the State of Cloud Computing
- Cloud Expo New York Call for Papers Deadline December 15
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- US Federal Government is Major Cloud Computing Innovator
- Google Wave
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Adaptivity & Cloud Computing: Exclusive Q&A with CEO Tony Bishop
- 4th International Cloud Expo: Photo Album
- The Top 150 Players in Cloud Computing
- SYS-CON.TV: Cloud Computing Expo Power Panel
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- 1st Annual GovIT Expo: Letter from the Technical Chair
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- Industry Experts Discuss the State of Cloud Computing
- SOA World Power Panel on SYS-CON.TV
- CIA was Headed to an Enterprise Cloud All Along: Jill Tummler Singer
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Cloud Expo New York Call for Papers Deadline December 15
- Stock in Focus: Dragon Capital
- The i-Technology Right Stuff
- Who Are The All-Time Heroes of i-Technology?
- Get the Message
- Where Are RIA Technologies Headed in 2008?
- i-Technology Viewpoint: Is Web 2.0 the Global SOA?
- i-Technology Viewpoint: Thinking Outside the VC Box
- ESB Myth Busters: 10 Enterprise Service Bus Myths Debunked
- i-Technology Viewpoint: When to Leave Your First IT Job
- SOA Web Services Edge Conference Coverage on SYS-CON.TV
- Five Reasons Why Web 2.0 Matters
- SYS-CON.TV's "SOA Web Services" and "Enterprise Open Source" Programs To Air in December
- SOA World Conference & Expo SYS-CON.TV Power Panel Live From Times Square










There are a variety of applications that supp...

























