使用kso​​ap2使用Web服务时出错?

时间:2014-11-13 14:04:47

标签: android web-services tomcat

我正在使用kso​​ap2库来使用Web服务(tomcat)。我可以在表中插入数据,但我无法理解为什么在LogCat中返回一些System.err并且我的方法总是返回false,因为传递了catch

这里我是怎么做的

public class UsuarioDAOws {

    private final String URL = "http://192.168.1.102:8080/ExemploWS/services/UsuarioDAO?wsdl";
    private final String NAMESPACE = "http://testepk.com.br"; //pacote no web service: br.com.testepk   
    private final String INSERT = "insert";

    public Boolean insert(Usuario u){
        SoapObject soo = new SoapObject(NAMESPACE, INSERT);

        SoapObject sooUser = new SoapObject(NAMESPACE, "u");
        sooUser.addProperty("nome" , u.getNome());
        sooUser.addProperty("idade", u.getIdade());     
        soo.addSoapObject(sooUser);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);     
        //envelope.dotNet = true;
        envelope.implicitTypes = true;
        envelope.setAddAdornments(false);
        envelope.setOutputSoapObject(soo);

        HttpTransportSE httpTransport = new HttpTransportSE(URL);       

        try {
            httpTransport.call("urn:" + INSERT, envelope);
            SoapPrimitive answer = (SoapPrimitive)envelope.getResponse();
            return Boolean.parseBoolean(answer.toString());
        } catch (HttpResponseException e) {             
                e.printStackTrace();
                return false;
        } catch (IOException e) {               
                e.printStackTrace();
                return false;
        } catch (XmlPullParserException e) {                
                e.printStackTrace();
                return false;
        }       

    }

}

这里所有的System.err

11-13 08:39:31.752: D/dalvikvm(1896): GC_FOR_ALLOC freed 113K, 6% free 2882K/3064K, paused 56ms, total 60ms
11-13 08:39:32.452: D/dalvikvm(1896): GC_FOR_ALLOC freed 403K, 14% free 2981K/3456K, paused 31ms, total 31ms
11-13 08:39:32.462: W/System.err(1896): Invalid stream or encoding: java.io.IOException: BufferedInputStream is closed (position:START_DOCUMENT null@1:1) caused by: java.io.IOException: BufferedInputStream is closed; nested exception is:
11-13 08:39:32.482: W/System.err(1896): java.io.IOException: BufferedInputStream is closed
11-13 08:39:32.482: W/System.err(1896):     at java.io.BufferedInputStream.streamClosed(BufferedInputStream.java:118)
11-13 08:39:32.482: W/System.err(1896):     at java.io.BufferedInputStream.read(BufferedInputStream.java:223)
11-13 08:39:32.492: W/System.err(1896):     at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1633)
11-13 08:39:32.502: W/System.err(1896):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:117)
11-13 08:39:32.502: W/System.err(1896):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:275)
11-13 08:39:32.502: W/System.err(1896):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
11-13 08:39:32.502: W/System.err(1896):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
11-13 08:39:32.502: W/System.err(1896):     at com.example.testaws.UsuarioDAOws.insert(UsuarioDAOws.java:37)
11-13 08:39:32.512: W/System.err(1896):     at com.example.testaws.MainActivity.onCreate(MainActivity.java:26)
11-13 08:39:32.512: W/System.err(1896):     at android.app.Activity.performCreate(Activity.java:5231)
11-13 08:39:32.512: W/System.err(1896):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-13 08:39:32.512: W/System.err(1896):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-13 08:39:32.512: W/System.err(1896):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-13 08:39:32.512: W/System.err(1896):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-13 08:39:32.512: W/System.err(1896):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-13 08:39:32.512: W/System.err(1896):     at android.os.Handler.dispatchMessage(Handler.java:102)
11-13 08:39:32.512: W/System.err(1896):     at android.os.Looper.loop(Looper.java:136)
11-13 08:39:32.512: W/System.err(1896):     at android.app.ActivityThread.main(ActivityThread.java:5017)
11-13 08:39:32.512: W/System.err(1896):     at java.lang.reflect.Method.invokeNative(Native Method)
11-13 08:39:32.512: W/System.err(1896):     at java.lang.reflect.Method.invoke(Method.java:515)
11-13 08:39:32.512: W/System.err(1896):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-13 08:39:32.512: W/System.err(1896):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-13 08:39:32.512: W/System.err(1896):     at dalvik.system.NativeStart.main(Native Method)
11-13 08:39:32.512: I/INSERT:(1896): false
11-13 08:39:33.202: D/gralloc_goldfish(1896): Emulator without GPU emulation detected.

0 个答案:

没有答案