我如何能在Android上肥皂发送和接收的Hashmap从web服务 [英] How can i send and receive Hashmap from Webservice with Soap on Android
问题描述
这是我的code:
public class PostSoap extends AsyncTask<HashMap<String, String>, Void, HashMap<String, String> >{
private String Tag= "PostSoap";
final static String NAMESPACE = "http://wwyw.unimportant.com/";
final static String METHOD_NAME = "unimportant";
final static String SOAP_ACTION = "http://wwyw.adsdsad.com/unimportan";
final static String URL = "http://unimportant:80/Service.asmx";
@Override
protected HashMap<String, String> doInBackground(
HashMap<String, String>... params) {
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
request.addProperty("obj",params[0]);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
Log.i(Tag,"soapenv..");
HttpTransportSE aht = new HttpTransportSE(URL);
Log.i(Tag,"httptransport");
try { aht.call(SOAP_ACTION, soapEnvelope); }catch(Exception e){ e.printStackTrace(); return null; }
try { return ""+?????????;}catch(Exception e){ e.printStackTrace(); return null; }
}
protected void onPostExecute(HashMap<bool,String> dyr) {
if (dyr == null) { Toast.makeText( , "error.", Toast.LENGTH_SHORT).show(); return; } //
try { Toast.makeText( , " "+dyr, Toast.LENGTH_LONG).show(); }catch(Exception e){ } //
}
}
我知道有太多的失败,在这个code。我要发送到要求为的HashMap
,也希望得到一个的HashMap
。我怎样才能做到这一点。我需要了解更多这方面的建议。结果预先感谢您:)
I know there are too many fail in this code. I want to send to request as a HashMap
and also want to receive as a HashMap
. How can I do it. I need more advice about this.
Thank you in advance:)
推荐答案
您可以通过你得到的输入,这些键/值添加到SoapObject HashMap中循环。当您收到来自服务器的响应,则需要根据SOAP方法的输出格式解析的结果,并将其填充到一个新的HashMap或一个ArrayList对象(取决于你的需要)创建。如果您创建应用程序的服务器端属于你,你可以回到它的格式为XML或JSON字符串。这将使它更容易解析为一个对象。
You can loop through the HashMap you got as input to add those key/values to SoapObject. After you recieve the response from the server, you need to parse the result according to the soap method's output format and fill them into a new HashMap or to an ArrayList object(depends on your needs) you create. If the server side of the application you create belongs to you, you can return a string which is formatted as XML or JSON. That would make it easier to parse into an object.
这篇关于我如何能在Android上肥皂发送和接收的Hashmap从web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!