我正在测试一个使用KSOAP2库的android应用程序,而我试图将对象ArrayList发送到我的Web服务应用程序,这是在netbeans中进行的,其方法是接收此List并返回响应的方法。
我一直在搜索有关如何测试Web服务的信息,因为netbeans使用默认服务器(glassfish),而我使用过tomcat的netbeans项目,所以我找到了SOAP UI程序来测试此方法,并且在通过SOAP UI请求,方法响应成功,它也应该返回一个对象列表,但是现在就可以了,
在android中,我试图发送此ArrayList像这样:
private final String SOAP_NAMESPACE = "http://ws.soap.net/";
private final String URL_SOAP="http://MI_IP:PORT/GetSomeRest/WebServiceTest";
private final String SOAP_SOMETHING = "GetSomething";
private final String SOAP_ACTION_GETSOMETHING = "http://ws.soap.net/" + SOAP_SOMETHING;
public SoapObject SendSigns(ArrayList paramSigns)
{
SoapObject request = new SoapObject(SOAP_NAMESPACE, SOAP_SOMETHING);
request.addSoapObject(buildArray(paramSigns));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
new MarshalBase64().register(envelope);
envelope.bodyOut = request;
envelope.setOutputSoapObject(request);
envelope.setAddAdornments(false);
envelope.implicitTypes= true;
envelope.dotNet=true;
envelope.headerOut = new org.kxml2.kdom.Element[1];
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_SOAP);
try {
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION_GETSOMETHING, envelope);
SoapObject Object = (SoapObject) envelope.getResponse();
if(Object!=null)
{
return Object;
}
} catch (Exception e) {
Log.d("CALL DUMP", "requestError: "+androidHttpTransport.requestDump);
Log.d("CALL DUMP", "responseEror: "+androidHttpTransport.responseDump);
Log.e("ERROR: ", String.valueOf(e));
}
return null;
}
这是buildArray方法,该方法返回填充了列表的SoapObject:
protected SoapObject buildArray(ArrayList paramSigns) {
SoapObject soapSigns = new SoapObject(SOAP_NAMESPACE, "List");
for (int i = 0; i < Signs.size(); i++) {
paramSigns.addProperty("id",Signs.get(i).getId());
paramSigns.addProperty("type",Signs.get(i).getType());
}
return soapSigns;
}
因此,当我运行我的应用程序时,出现以下错误:
java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“ void org.kxml2.kdom.Element.write(org.xmlpull.v1.XmlSerializer)”
但是如果
如果我删除以下行:
envelope.headerOut = new org.kxml2.kdom.Element[1];
我收到了来自Web服务的响应,但带有soapObject Null,并且我把这一行:
androidHttpTransport.debug = true;
我看到requestDump充满了这样的XML:
xmlns:d="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
386661006
sign
68235000
sign
25064002
sign
我将此XML粘贴到SOAP UI请求中,但没有响应...
因此,我如何面对java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“ void org.kxml2.kdom.Element.write(org.xmlpull.v1.XmlSerializer)”?
各种各样的帮助,我将不胜感激!
最好的祝福