微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

关于ksoap连接webService的问题

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;
	}@H_502_5@  此处要注意的一点是,如果webservice的返回值是byte类型的,应该用SoapObject result =(SoapObject)envelope.bodyIn;//getResponse(); 如果是String类型的则用 Object result=envelope.bodyIn; 否则会报错!
        

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐