public byte[] getTranferFileString(String filename,int ImageType,int index)
{
String fileContent = "";
String fileContent1="";
byte[] data=null;
//参数表示为 WebService命名空间,第二个参数为WebService里面的方法名称
SoapObject soapObject = new SoapObject(targetNameSpace,getTranferFileStringWithEncode);
//soapObject.addProperty("str", "fuck it");
soapObject.addProperty("ImageType",ImageType );
soapObject.addProperty("index", index);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//增加参数
envelope.dotNet = false;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE httpTranstation=new HttpTransportSE(WSDL);
try {
//使用call 方法调用webservice方法
httpTranstation.call(null, envelope);
//httpTranstation.call(null, envelope);
Object result =envelope.bodyIn;//getResponse();
fileContent=result.toString();
fileContent1=fileContent.substring(40, fileContent.length());
//fileContent=result.toString();
//String strFile="downfromserive"+Math.random()+".png";
data=FileOperate.jiemi(fileContent1);
//FileOperate.xmlString2Bin(fileContent1, new File(filename));
// 也可以通过下面方式获得str
// SoapPrimitive result = (SoapPrimitive ) envelope.getResponse();
// str=result.toString();
// 直指value字符串值
} catch (IOException e) {
e.printStackTrace();
Log.i("AppClient", "UpAndDown.java"+e.toString());
} catch (XmlPullParserException e) {
e.printStackTrace();
Log.i("AppClient", "UpAndDown.java"+e.toString());
}
return data;
}
此处要注意的一点是,如果webservice的返回值是byte类型的,应该用SoapObject result =(SoapObject)envelope.bodyIn;//getResponse(); 如果是String类型的则用 Object result=envelope.bodyIn; 否则会报错!