Académique Documents
Professionnel Documents
Culture Documents
Summary: The SOAP with Attachments specification (see Resources) defines how to
send binary attachments along with a SOAP message. But there may be cases where you
do not want to use attachments to send binary data. For instance, Microsoft's .NET Web
services engine does not support Sw/A, so if you want to interoperate with .NET, you
must use some other alternative. Learn a new way to modify an existing Web service that
uses attachments to send binary data to another service that does not.
Tag this!
Update My dW interests (Log in | What's this?) Skip to help for Update My dW interests
There are a number of ways to exchange binary data other than through SOAP with
Attachments (Sw/A). We briefly mention a couple of complex methods, but then go into
details about the simplest method.
If your Web service implementation supports DIME, then you could write a wrapper
WSDL whose binding deals with the DIME protocol instead of the Sw/A protocol. There
are two big concerns with this approach, however:
• The DIME note in W3C expired at the end of 2002, so there is no official
specification for what is called DIME. Without an official specification, it is
unlikely anyone other than Microsoft will continue to support this protocol.
• There is no official WSDL binding for DIME. Without an official WSDL binding,
it is unlikely a given binding will be supported by all vendors and, therefore,
DIME bindings would not interoperate.
Back to top
Back to top
A non-attachment solution
Back to top
A detailed example
Assume you have a legacy Web service with the interface in Listing 1.
So far, so good. But now you come to the hard part: the actual implementation of the
wrapper. The wrapper implementation must convert between byte[] and
java.awt.Image before delegating the method calls to the real service. See Listing 3 for
a complete implementation of the wrapper API. This is one possible J2SE 1.4 solution. It
is rather complex, and while it is not the purpose of this tip to explain in detail how to
convert between byte[] and java.awt.Image, we present it here for your information.
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
The client-side situation is similar to the server-side situation. You want to convert
between byte[] and java.awt.Image. So the client-side code is similar to the server-
side code. (See the zip file that comes with this tip (click on the code icon at the top or
bottom of this tip) for some actual client-side code.)
The other JAX-RPC-supported attachment types all map to Java types which you can
convert to and from a byte[] (usually through a stream). So while the implementations
for each type will be different than this example, the basic idea is the same.
Back to top
A sample client
Since one primary reason for converting a binary attachment to inlined binary data is
that .NET doesn't support Sw/A, we chose to show you a C# client for this service as
well. In this case, we build a client based on the .NET Framework SDK version 1.1.
The C# client code in Listing 4 loads an image from the file system and sends it to the
server through the available sendImage(byte[] i) operation. Once sent, the client
retreives the same image using the getImage() operation and saves it to the file system
with a different name.
namespace ImageClient
{
class ImageClient
{
[STAThread]
static void Main(string[] args)
{
if (args.Length < 4) {
Console.WriteLine("Insufficient argument list:
<host> " +
"<port> <sendImageName> <newImageName>");
}
else {
string host = args[0];
string port = args[1];
string sendImageName = args[2];
string newImageName = args[3];
ImageBagWithNoAttachmentsService service =
new ImageBagWithNoAttachmentsService();
service.Url = "http://" + host + ":" + port +
"/AttachmentWar/services/ImageBagWithNoAttachment
s";
Console.WriteLine("");
Back to top
Summary
There are a number of ways that you can send binary data other than through Sw/A. In
this tip we detailed the simplest: inlining the binary data using xsd:hexBinary. We
wrapped a service using java.awt.Image with a service using xsd:hexBinary.
Back to top
Download
Resources
• Download the client code and the EAR file associated with this article by clicking
on the code icon at the top or bottom of this tip. The EAR file contains both the
attachment service, and the byte[] wrapper service.
• Learn more about Passing files to a Web service in this tip (developerWorks,
February 2004).
• Learn how to create a .NET Web services client proxy with this article from
MSDN.
• Access Web services knowledge, tools, and skills with Speed-start Web services,
which offers the latest Java-based software development tools and middleware
from IBM (trial editions), plus online tutorials and articles, and an online
technical forum.
• Want more? The developerWorks SOA and Web services zone hosts hundreds of
informative articles and introductory, intermediate, and advanced tutorials on how
to develop Web services applications.
Nicholas Gallardo works as a software engineer on the IBM WebSphere Web Services
engine, where he is focused on serviceability and interoperability. Nicholas came to IBM
in 2001 after contributing development efforts to two different technology start-ups in
Austin, Texas.
Russell Butek is an IBM Web services consultant and is one of the developers of the IBM
WebSphere Web services engine. He is also the IBM representative on the JAX-RPC
Java Specification Request (JSR) expert group. He was involved in the implementation of
Apache's AXIS SOAP engine, driving AXIS 1.0 to comply with JAX-RPC 1.0.
Previously, he was a developer of the IBM CORBA ORB and an IBM representative on a
number of OMG task forces: the portable interceptor task force (of which he was chair),
the core task force, and the interoperability task force.