How to configure a web services typemapping to use Base64 rather than ArrayOfByte when returning a byte[] as a response?

概要: How to configure a web services typemapping to use Base64 rather than ArrayOfByte when returning a byte[] as a response?

Issue:

When a byte[] is returned as a Web Services response, each byte is defined on a single line of xml, which generates a lot of (xml) overhead when working with large arrays. How can this be avoided?

-----------------------------------------------

Example response:

<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:LicensingFacadeResult" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://integration.pro.pub.protection.jp.com">
<deliveryType href="#id1"/>
<myBytes soapenc:arrayType="xsd:byte[80000]" xsi:type="soapenc:Array">
<myBytes href="#id2"/>
<myBytes href="#id3"/>

<myBytes href="#id4"/>
<myBytes href="#id5"/>
<myBytes href="#id6"/>
...
<myBytes href="#id80000"/>

-----------------------------------------------

Solution:

Use a Base64 serializer/deserializer rather than the default Array serializer/deserializer.

Go to Web Services Designer | click on Axis Flow tab | go to Structure Pane on the left | Deployment Services | <Service Name> | TypeMapping | ArrayOfByte | Double Click to edit | Change serializer/deserializer (see below) | uncheck: Regenerate Element on Source Change | Rebuild

from:

org.apache.axis.encoding.ser.ArraySerializerFactory

to:

org.apache.axis.encoding.ser.Base64SerializerFactory

-----------------------------------------------

Example response:

<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:TestResponce" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://test">
<bytes xsi:type="xsd:base64Binary">AQIDBAUGBwg=</bytes>
<deliveryType xsi:type="xsd:int">123</deliveryType>
<message xsi:type="xsd:string">OK</message>
</multiRef>

-----------------------------------------------