views:

274

answers:

1

Hi I have made a small example to show my problem. Here is my web-service:

package service;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class BytesService {

 @WebMethod
 public String redirectString(String string){
  return string+" - is what you sended";
 }

 @WebMethod
 public byte[] redirectBytes(byte[] bytes) {
  System.out.println("### redirectBytes");
  System.out.println("### bytes lenght:" + bytes.length);
  System.out.println("### message" + new String(bytes));
  return bytes;
 }

 @WebMethod
 public byte[] genBytes() {
  byte[] bytes = "Hello".getBytes();
  return bytes;
 }

}

I pack it in jar file and store in "axis2-1.5.1/repository/servicejars" folder. Then I generate client Proxy using Eclipse for EE default utils. And use it in my code in the following way:

  BytesService service = new BytesServiceProxy();
  System.out.println("Redirect string");
  System.out.println(service.redirectString("Hello"));
  System.out.println("Redirect bytes");
  byte[] param = { (byte)21, (byte)22, (byte)23 };
  System.out.println(param.length);
  param = service.redirectBytes(param);
  System.out.println(param.length);
  System.out.println("Gen bytes");
  param = service.genBytes();
  System.out.println(param.length);

And here is what my client prints:

Redirect string
Hello - is what you sended
Redirect bytes
3
0
Gen bytes
5

And on server I have:

### redirectBytes
### bytes lenght:0
### message

So byte array can normally be transfered from service, but is not accepted from the client. And it works fine with strings. Now I use Base64Encoder, but I dislike this solution.

A: 

I suspect the problem is in serializing the byte-array into an XML SOAP message. The XML tag in the originating SOAP message is possibly zero bytes. I'd recommend using the SOAP monitor to take a peek at the message being sent to your web service.

You may dislike the idea of encoding the byte-arry in transit, however, you need to consider it binary data. For example what if someone sent you a SOAP message encoded in something other than UTF-8? You'll want to avoid the possibility of the byte-array data changing (conversion between character sets) when the SOAP message is parsed.

Mark O'Connor