将ArrayList从Android发送到SOAP并获得错误:org.kxml2.kdom.Element.write(org.xmlpull.v1.XmlSerializer)

x33g5p2x  于 2023-08-01  发布在  Android
关注(0)|答案(1)|浏览(90)

我正在测试一个使用KSOAP 2库的Android应用程序,我试图发送一个对象ArrayList到我的Web服务应用程序,该应用程序位于netbeans中,具有接收此List并返回响应的方法。
我正在搜索有关如何测试Web服务的信息,因为netbeans使用默认服务器(glassfish),而我拥有的netbeans项目使用tomcat,所以我找到了SOAP UI程序来测试此方法,当我通过SOAP UI请求传递列表时,方法响应成功,它也应该返回一个对象的LIST,从现在开始就可以了,但是,
在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<Signs> 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方法,它返回一个填充了List的SoapObject:

protected SoapObject buildArray(ArrayList<Signs> 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:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:d="http://www.w3.org/2001/XMLSchema" 
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<GetSomething xmlns="http://ws.soap.net/">
<List>
<id>386661006</id>
<tipo>sign</tipo>
<id>68235000</id>
<tipo>sign</tipo>
<id>25064002</id>
<tipo>sign</tipo>
</List>
</GetSomething>
</v:Body>
</v:Envelope>


我将这个XML粘贴到SOAPUI请求中,但没有得到响应……
那么我该如何面对java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“void org.kxml2.kdom.Element.write(org.xmlpull.v1.XmlSerializer)”?
我将非常感谢所有的帮助!
最好的问候

7qhs6swi

7qhs6swi1#

好吧,伙计们,问题就出在这条线上:

envelope.headerOut = new org.kxml2.kdom.Element[1];

字符串
因为我认为我的Web服务没有Header!
这是避免错误的方法。。
最好的问候!

相关问题