[英]Android: how to create ksoap2 request?
我嘗試了解如何在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
能否請您舉一個簡單的請求來了解它是如何工作的?
Solutuion:
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中的類型,那么順序很重要
您還可以嘗試在線生成器工具,它可以生成連接到WS所需的所有類。 我最近使用過http://easywsdl.com ,我的工作就像一個魅力。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.