关于ksoap连接webService的问题
发布时间:2020-12-17 01:13:27 所属栏目:安全 来源:网络整理
导读:public byte[] getTranferFileString(String filename,int ImageType,int index){String fileContent = "";String fileContent1="";byte[] data=null;//参数表示为 WebService命名空间,第二个参数为WebService里面的方法名称SoapObject soapObject = new So
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; 否则会报错! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |