我试着了解如何在Android上使用ksoap。我已经执行了这个ksoap请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:namespace">
<soapenv:Header/>
<soapenv:Body>
<urn:"method name">
<urn:mode>"value"</urn:mode>
</urn:method name>
</soapenv:Body>
</soapenv:Envelope>
通过AndroidHttpClient在HttpPost的实体部分。我尝试用ksoap做类似的事情:
SoapObject root = new SoapObject(NAMESPACE, "method name");
PropertyInfo pr = new PropertyInfo();
mode.setName("mode");
mode.setValue("value");
root.addProperty(pr);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(root/*request*/);
Log.d(TAG, envelope.toString());
HttpTransportSE transport = new HttpTransportSE(url);
try {
transport.call(NAMESPACE.concat("/").concat("method name"), envelope);
Object obj = (Entity) envelope.getResponse();
,但我有一个例外
SoapFault - faultcode: 'SOAP-ENV:Server' faultstring: 'Processing Failure' faultactor: 'null' detail: org.kxml2.kdom.Node@44f7cab0
请您举一个这个简单请求的例子来了解它是如何工作的?
答案 0 :(得分:2)
<强>解决方案:强>
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;
SoapObject root = new SoapObject(NAMESPACE, "method name");
PropertyInfo mode = new PropertyInfo();
mode.setNamespace(NAMESPACE);
mode.setName("mode");
mode.setValue("value");
mode.setType(String.class);
root.addProperty (mode);
//root.addProperty("mode", "value");
envelope.setOutputSoapObject(root/*request*/);
Log.d(TAG, envelope.toString());
HttpTransportSE transport = new HttpTransportSE(url);
transport.debug = true;
try {
transport.call(NAMESPACE.concat("/").concat("Method of server"), envelope);
Log.d(Qube.TAG, transport.requestDump);
Log.d(Qube.TAG, transport.responseDump);
*如果你想避免xml
中的类型,那么顺序很重要答案 1 :(得分:0)
您还可以尝试在线生成器工具,该工具可以生成连接到WS所需的所有类。我最近使用http://easywsdl.com,我的工作就像一个魅力。