ksoap2 android sending data

早过忘川 提交于 2019-12-13 06:32:57

问题


I'm trying to get ksoap2 working on android. I have spent at least 10 hours now reading forum posts, and documentations. Just querying some methods like getServerTime where I don't have to send any values, works. My goal is to send data, and receive a response. For example: send city name, get city time.

I'm practicing on this site: http://www.nanonull.com/TimeService/TimeService.asmx

this is my code:

  String METHOD_NAME = "getCityTime";
  String SOAP_ACTION = "http://www.Nanonull.com/TimeService/getCityTime";
  String NAMESPACE = "http://www.nanonull.com/TimeService/";
  String URL = "http://www.nanonull.com/TimeService/TimeService.asmx";

  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

  request.addProperty("city", "Chicago");

  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER11);

  envelope.setOutputSoapObject(request);

  HttpTransportSE httpTransport = new HttpTransportSE(URL);
  try {
   httpTransport.call(SOAP_ACTION, envelope);
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (XmlPullParserException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } // This sends a soap

  System.out.println(envelope.bodyIn.toString());

this is the error I get(envelope.bodyIn.toString()):

SoapFault - faultcode: 'soap:Server'
faultstring: 'Server was unable to process request. ---> Object reference not set to an
instance of an object.' faultactor: 'null' detail: org.kxml2.kdom.Node@435b9cf8

Help would be greatly appreciated.


回答1:


Try

   envelope.dotNet = true;



回答2:


I got the answer! The server is faulty, something is wrong on the server side! :(

I tried another service(http://footballpool.dataaccess.eu/data/info.wso?), and it works like a charm.




回答3:


I made an article about the topic

http://www.helloandroid.com/tutorials/using-ksoap2-android-and-parsing-output-data




回答4:


 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

soapobjet sp = new soapobject("http://www.nanonull.com/TimeService/","getCityTime");
sp.addproperty("city", "Chicago");

request.addsoapobject(sp);


来源:https://stackoverflow.com/questions/3093860/ksoap2-android-sending-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!