ksoap2 android发送数据

时间:2010-06-22 14:03:07

标签: java android soap ksoap2

我正在努力让ksoap2在Android上运行。我现在花了至少10个小时阅读论坛帖子和文件。 只是查询一些方法,比如getServerTime,我不需要发送任何值,工作。 我的目标是发送数据并收到回复。例如:发送城市名称,获取城市时间。

我正在这个网站上练习:http://www.nanonull.com/TimeService/TimeService.asmx

这是我的代码:

  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());

这是我得到的错误(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

非常感谢帮助。

4 个答案:

答案 0 :(得分:1)

尝试

   envelope.dotNet = true;

答案 1 :(得分:1)

我得到了答案! 服务器出现故障,服务器端出错了! :(

我尝试了另一项服务(http://footballpool.dataaccess.eu/data/info.wso?),它就像一个魅力。

答案 2 :(得分:0)

答案 3 :(得分:0)

 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

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

request.addsoapobject(sp);