Failed sending bytes array to JAX-WS web service on Axis

Posted by user304309 on Stack Overflow See other posts from Stack Overflow or by user304309
Published on 2010-03-31T08:48:19Z Indexed on 2010/03/31 8:53 UTC
Read the original article Hit count: 754

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about web-services