webServices传输数据时发生丢数据现象,本地传输也是,为什么? 用一个webServices传一个byte数组,传过去的byte数组的length大小跟原本的byte数组的length的大小不一样。为什么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用一个webServices传一个byte数组,传过去的byte数组的length大小跟原本的byte数组的length的大小不一样 ?我也是传 byte [] 啊 ,没有看到不一样啊 ,axis框架写的 是的。你的byte是什么文件解析成的?我是从一个zip文件读成byte数组的。 呀lz,幸亏你遇见我了,帮你解答吧。读zip的时候用这个 int len = 0; byte[] bytes = new byte[256]; while((len = in.read(bytes, 0, bytes.length)) != -1) { out.write(bytes, 0, len); } out.flush(); out.close(); in.close(); 我就是用的这个啊。但是不行,你的in是fileinputstream是吧?out是ByteArrayOutPutStream是吧? 把你的outputstream相关代码贴出来。 这是客户端public class Client { public static void main(String [] args){ String path = "C:\\Users\\Andy\\Desktop\\01.gif"; byte [] b = ReadFileToArrayByte.read(path); String url = "http://127.0.0.1:8888/TestServer/services/Test?wsdl"; try { TestStub tstub = new TestStub(url); SendArraybyte sendbyte = new SendArraybyte(); System.out.println(b.length); sendbyte.setSend(b); SendArraybyteResponse res = tstub.sendArraybyte(sendbyte); String ress = res.getOut(); System.out.println(ress); } catch (AxisFault e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}这是服务端 public org.example.www.test.SendArraybyteResponse sendArraybyte ( org.example.www.test.SendArraybyte sendArraybyte ) { //TODO : fill this with the necessary business logic SendArraybyteResponse res = new SendArraybyteResponse(); byte[] b = sendArraybyte.getSend(); System.out.println(b.length); String path = "C:\\Users\\Andy\\Desktop\\02.gif"; WriteArrayByteToFile.write(b, path); res.setOut("成功!"); return res; } }而且我现在发现传压缩过的东西就会出问题。 我希望看到ReadFileToArrayByte.read(path)这个方法。 WebService 一般用的是 SOAP 协议,SOAP 是 XML 协议,XML 中能放二进制数据么? 我已经解决这个问题了。传二进制文件不能用byte数组,只能用base64Binary这个数据类型。然后用DataHandler这个类封装文件的DataSource进行传输。谢谢大家的热情解答。 RSA加解密报错问题!!! json转换问题(使用Gson包) java 反射问题 html:text 如何过滤html代码? hibernate 提问 在struts的模型组件里如何获取DataSource? hibernate3关联时出现的the owning Session was closed如何处理? 关于cmp的问题-----------------基础.....求回答===========急 拦截器和过滤器的区别 谁有JBoss的examples?我没找到。 Quartz随spring自动加载 如何通过http上传多张图片及文字?
byte[] bytes = new byte[256]; while((len = in.read(bytes, 0, bytes.length)) != -1) {
out.write(bytes, 0, len);
} out.flush();
out.close();
in.close();
public static void main(String [] args){
String path = "C:\\Users\\Andy\\Desktop\\01.gif";
byte [] b = ReadFileToArrayByte.read(path);
String url = "http://127.0.0.1:8888/TestServer/services/Test?wsdl";
try {
TestStub tstub = new TestStub(url);
SendArraybyte sendbyte = new SendArraybyte();
System.out.println(b.length);
sendbyte.setSend(b);
SendArraybyteResponse res = tstub.sendArraybyte(sendbyte);
String ress = res.getOut();
System.out.println(ress);
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}这是服务端 public org.example.www.test.SendArraybyteResponse sendArraybyte
(
org.example.www.test.SendArraybyte sendArraybyte
)
{
//TODO : fill this with the necessary business logic
SendArraybyteResponse res = new SendArraybyteResponse();
byte[] b = sendArraybyte.getSend();
System.out.println(b.length);
String path = "C:\\Users\\Andy\\Desktop\\02.gif";
WriteArrayByteToFile.write(b, path);
res.setOut("成功!");
return res;
}
}而且我现在发现传压缩过的东西就会出问题。