嗨我想使用上面的肥皂xml请求肥皂
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style"> <soapenv:header/> <soapenv:Body> <urn:AvailCheck> <IUvail> <Unit>PC</Unit> <Qty>3000</Qty> </IUvail> </urn:AvailCheck> </soapenv:Body></soapenv:Envelope>
所以我使用ksoap库创建了一个代码.我为soapobject创建了一个对象
SoapObject request = new SoapObject(nameSPACE, METHOD_name);
并添加了这样的属性
request.addProperty("Unit", "PC");request.addProperty("Qty", "3000");
但问题是我无法添加< IUvail>在requset ..所以我怎么能添加这个?
解决方法:
你可以像这样传递一个复杂的对象(IUvail):
IUvail.java
import java.util.Hashtable;import org.ksoap2.serialization.KvmSerializable;import org.ksoap2.serialization.PropertyInfo;import org.ksoap2.serialization.soapObject;public class IUvail implements KvmSerializable { private String unit; private int qty;public IUvail() {}public IUvail(String unit, int qty) { this.unit = unit; this.qty = qty;}public voID setUnit(String unit) { this.unit = unit; }public voID setQty(int qty) { this.qty = qty;}public String getUniy() { return unit;}public int getQty() { return qty;}public Object getProperty(int arg0) { switch(arg0) { case 0: return unit; case 1: return qty; } return null;}public int getPropertyCount() { return 2;}public voID getPropertyInfo(int index, Hashtable arg1, PropertyInfo propertyInfo) { switch(index){ case 0: propertyInfo.name = "unit"; propertyInfo.type = PropertyInfo.STRING_CLASS; break; case 1: propertyInfo.name = "qty"; propertyInfo.type = PropertyInfo.INTEGER_CLASS; break; default: break; }}public voID setProperty(int index, Object value) { switch(index) { case 0: this.unit = value.toString(); break; case 1: this.qty = Integer.parseInt(value.toString()); break; default: break; }} }
然后
SoapObject request = new SoapObject(nameSPACE, METHOD_name);IUvail iuvail = new IUvail();iuvail.setUnit("PC");iuvail.setQty(3000);request.addProperty("IUvail", iuvail);SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11);envelope.dotNet = true;envelope.setoutputSoapObject(request);envelope.addMapPing(TARGET_nameSPACE, "IUvail", new IUvail.getClass());AndroIDhttpTransport transport = new AndroIDhttpTransport(URL);try { transport.call(nameSPACE + METHOD_name, envelope); /* Get the response: it depends on your web service implementation */} catch (Exception e) { e.printstacktrace();}
nameSPACE,URL,METHOD_name和TARGET_nameSPACE取决于您的ws.
总结以上是内存溢出为你收集整理的android – 在Ksoap2中的标记内嵌套属性全部内容,希望文章能够帮你解决android – 在Ksoap2中的标记内嵌套属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)