What is this?

This extension brings plain old DIME encoding to JAX-WS. DIME is an old-fashioned format for binary web service attachments and was superseded by SwaRef and MTOM. So, why you want to use it anyway?

Well, there are some web service clients out there, that cannot use Swaref or MTOM, but have support for DIME. One prominent member of this category it MS Office up to version 2003. If you have a newer Office version (i.e. 2007), then use the .Net framework with MTOM support on the client side and be happy. However, if you are like me and work for a company that still uses Office 2003 and you want to consume web services from VBA macros, then this is the right extension for you.

The extension only provides server-side support for DIME because nobody would ever want to write a Java web service client that sends binary attachments in DIME format. The main purpose of the extension is to have a VBA macro in Office 2003 on the client side and a Java web service provider using JAX-WS.

How does it work?

A DIME message consists of one or more records. The first record always contains a SOAP 1.1 message. Any other records contain a binary attachment that is referenced from the SOAP message via a href attribute.

Sample Service Provider

Here is a simple web service that has two methods. One that takes a file argument and one that returns a file result. In JAX-WS binary attachments are specified as javax.activation.DataHandler objects. There are three things to note about this class:

  1. The web service uses rpc style. This isn't strictly necessary, but Office 2003 likes it.
  2. The binding type is set to DimeBindingID.DIME_BINDING . This enables the DIME encoding for the service.
  3. Each method that returns a binary attachment gets a DimeOutput annotation. Likewise, earch method that takes a binary attachments as an argument gets a DimeInput annotation.
@WebService
@SOAPBinding(style = Style.RPC)
@BindingType(DimeBindingID.DIME_BINDING)
public class Dime {
    @WebMethod
    @DimeOutput
    public DataHandler getFile() {
        final URL url = getClass().getResource("/images/javaxml-duke.gif");
        final DataHandler data = new DataHandler(url);
        return data;
    }

    @WebMethod
    @DimeInput
    public void setFile(@WebParam(name = "data") final DataHandler data) {
        try {
            data.writeTo(new FileOutputStream("/tmp/dummy.gif"));
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
}

The SOAP result message from the getFile() method looks like this on the wire:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
                <ns2:getFileResponse xmlns:ns2="http://dime.ws.sample.org/">
                        <return href="uuid:c6777781-1b6b-4709-a147-f516357ea0c3"></return>
                </ns2:getFileResponse>
        </soap:Body>
</soap:Envelope>

The SOAP message is the first record of the DIME message. The second record contains the data of the binary attachment referenced by the content id uuid:c6777781-1b6b-4709-a147-f516357ea0c3 . Likewise the SOAP request message for the setFile() method looks like this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
                <ns2:setFile xmlns:ns2="http://dime.ws.sample.org/">
                        <data href="uuid:C6A593AA-6A3D-4AA8-9440-24E7F2918B5A" />
                </ns2:setFile>
        </soap:Body>
</soap:Envelope>

Again, the actual data of the binary attachment is in the second DIME record referenced by the href attribute.

Sample Service Consumer

The sample service consumer is implemented as a VBA macro in Word 2003. Open the VBA editor using ALT-F11 in Word to see the code.

Sub test()
    Dim service As New DimeService
    Dim attachment As New FileAttachment30
    Dim result As IReceivedAttachment
    
    Set result = service.getFile
    result.SaveToFile "C:\Temp\dummy.gif", True
    
    attachment.FileName = "C:\Temp\dummy.gif"
    service.setFile attachment
End Sub

FileAttachment30 and IReceivedAttachment come with the SOAP Toolkit 3.0 runtime . DimeService is a VBA class that was generated by the SOAP Toolkit 3.0 SDK from the WSDL.

Private sc_DimeService As SoapClient30
Private Const c_WSDL_URL As String = "http://zaphod.treichels.de:8080/jaxws/services/dime?wsdl"
Private Const c_SERVICE As String = "DimeService"
Private Const c_PORT As String = "DimePort"
Private Const c_SERVICE_NAMESPACE As String = "http://dime.ws.sample.org/"

Private Sub Class_Initialize()
    Dim str_WSML As String
    str_WSML = ""

    Set sc_DimeService = New SoapClient30

    sc_DimeService.MSSoapInit2 c_WSDL_URL, str_WSML, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE
    sc_DimeService.ConnectorProperty("ProxyServer") = "<CURRENT_USER>"
    sc_DimeService.ConnectorProperty("EnableAutoProxy") = True
End Sub

Private Sub DimeServiceErrorHandler(str_Function As String)
    If sc_DimeService.FaultCode <> "" Then
        Err.Raise vbObjectError, str_Function, sc_DimeService.FaultString
    Else
        Err.Raise Err.Number, str_Function, Err.Description
    End If
End Sub

Public Function getFile() As IReceivedAttachment
    On Error GoTo getFileTrap
    Set getFile = sc_DimeService.getFile()
Exit Function

getFileTrap:
    DimeServiceErrorHandler "getFile"
End Function

Public Sub setFile(ByRef ar_data As IAttachment)
    On Error GoTo setFileTrap

    sc_DimeService.setFile ar_data

Exit Sub
setFileTrap:
    DimeServiceErrorHandler "setFile"
End Sub

Terms of Use; Privacy Policy; Copyright ©2013-2014 (revision 20140418.2d69abc)
 
 
Close
loading
Please Confirm
Close