Freigeben über


How to do MTOM Interop

In my JavaOne session yesterday I showed (what I believe to be) the first MTOM Interop demo between .NET and Java using publicly available toolkits.  For those that don't know MTOM (Message Transmission Optimization Mechanism) is the new specification for optimizing the transmission and/or wire format of SOAP messages.  Primarily this means that we have a new standard that allows the sending of attachments over Web Services - one that the industry agrees on, and one that is composable with the other WS-* specifications.

 

The demo showed WSE 3.0 CTP (which can be downloaded here) returning a PowerPoint deck to a Java client using JAX-WS EA 2.0 (which can be downloaded here).  This is how it works:

 

The WSE service defines a method called GetFileBinary:

 

[WebMethod]

public byte[] GetFileBinary(String fileName)

{
String filePath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\" + fileName;

  return File.ReadAllBytes(filePath);

}

 

As you can see the method returns an array of bytes.  To enable MTOM encoding we use the following switch in the web.config file:

 

<mtom clientMode="On" />

 

When we call the method the binary representation of the attachment appears within the body of the SOAP response (although actually this is an abstract representation of the multiple MIME messages that are physically sent on the wire). 

 

So, how do we call this in Java?  Well, first we create a new instance of the service using JAX-WS EA 2.0 and call the GetFileBinary method:

 

ServiceFactory serviceFactory = ServiceFactory.newInstance();

Service service = (Service)serviceFactory.createService(new URL("https://localhost:8080/dotNETWS/Service.asmx?WSDL"), Service.class);

ServiceSoap soap = service.getServiceSoap();

SOAPBinding binding = (SOAPBinding)((BindingProvider)soap).getBinding();

binding.setMTOMEnabled(true);

 

Notice how we also set the MTOMEnabled flag on the binding of the service.  When the method is called, an array of bytes is returned.  We simply output to a FileOutputStream:

 

byte[] fileData = soap.getFileBinary("JavaOne.ppt");

FileOutputStream fos = new FileOutputStream("C:\\Documents and Settings\\Administrator\\Desktop\\JavaOne.ppt");

fos.write(fileData);

fos.flush();

fos.close();

 

..and there we have the attachment!  Anyone that has done anything with SwA or DIME interop in the past will hopefully recognize the progress that we are making in this area - testament I believe to how Microsoft and Sun has been working together on these specifications.  From a presenter's point of view, it was also nice to see how easy this demo was to put together (even if it was done just a few hours before my presentation ;-)

 

What's next?  I am working with Arun Gupta from Sun to formally write up the demo into a whitepaper and sample download that we'll post on both sites.  After that we'll be working on showing Secure MTOM (WS-Security + MTOM) to demonstrate how attachments can be sent securely between Web Service endpoints.

Comments

  • Anonymous
    July 01, 2005

    A Simple Resource Helper Class [Via:
    jehance ]
    ASP.NET Today: Frames and Grids [Via:
    DinoE ]...
  • Anonymous
    July 01, 2005

    A Simple Resource Helper Class [Via:
    jehance ]
    ASP.NET Today: Frames and Grids [Via:
    DinoE ]...
  • Anonymous
    July 02, 2005
    FYI: the chat with dims and me posted on the dev list .. added for the records sake!
    dims: is MTOM working?
    Srinath Perera: there was a problem it failed occasianlly
    dims: did they test it against WSE3.0CTP/.NET2.0?
    Srinath Perera: thilina tell he...
  • Anonymous
    July 11, 2005
    Slides from my JavaOne Birds-Of-Feather
  • Anonymous
    July 11, 2005
    Slides from my JavaOne Birds-Of-Feather
  • Anonymous
    July 14, 2005
    For those that didn't get to attend my session at JavaOne or TechEd Europe this year, here is a 5 minute&amp;nbsp;&quot;blog...
  • Anonymous
    July 14, 2005
    #1: Apparently a mime boundary like &quot;----_AxIs2_Def_boundary_42214532&quot; is not acceptable, because it has 4 underscores as prefix. WSE wants only 2 underscores. #2: A long content-type is usually split into multiple lines, but WSE does not like it. it wants...
  • Anonymous
    August 10, 2005

    Here's an interesting Black Hat paper&amp;nbsp;detailing security considerations when deciding to use web...