无法将字节数组发送到Axis上的JAX-WS Web服务 [英] Failed sending bytes array to JAX-WS web service on Axis
问题描述
我举了一个小例子来说明我的问题.这是我的网络服务:
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;
}
}
我将其打包在jar文件中,并存储在"axis2-1.5.1/repository/servicejars"文件夹中.然后,我使用Eclipse for EE默认工具生成客户端代理.并通过以下方式在我的代码中使用它:
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
在服务器上,我有:
### redirectBytes
### bytes lenght:0
### message
因此字节数组通常可以从服务中传输,但不能从客户端接受.并且它可以很好地与字符串一起使用.现在,我使用Base64Encoder,但是我不喜欢这种解决方案.
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.
推荐答案
我怀疑问题在于将字节数组序列化为XML SOAP消息.原始SOAP消息中的XML标签可能为零字节.我建议使用SOAP监视器来窥视发送到Web服务的消息.
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.
您可能不喜欢对传输中的字节填充进行编码的想法,但是,您需要将其视为二进制数据.例如,如果有人向您发送了以UTF-8以外的其他方式编码的SOAP消息,该怎么办?您将希望避免解析SOAP消息时字节数组数据发生更改(字符集之间的转换)的可能性.
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.
这篇关于无法将字节数组发送到Axis上的JAX-WS Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!