android中的KSOAP webservices

时间:2012-05-09 07:42:46

标签: android ksoap2

我使用以下代码:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            envelope.dotNet=true;           
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);  
            try
            {
                androidHttpTransport.call(SOAP_ACTION, envelope);              
                SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
                Log.i("myApp", response.toString());  
                TextView tv = new TextView(this);
                tv.setText("message="+response.toString());
                setContentView(tv);                              
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }

网络服务正常运行,但显示以下错误:

W / System.err(975):---内部异常堆栈跟踪结束---'faultactor:'null'详细信息:org.kxml2.kdom.Node@44f1adb8  W / System.err(975):at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:116)  W / System.err(975):at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)  W / System.err(975):at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)  W / System.err(975):at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)  W / System.err(975):at com.redbus.SearchRoute.onCreate(SearchRoute.java:90)  W / System.err(975):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)  W / System.err(975):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)  W / System.err(975):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)  W / System.err(975):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)  W / System.err(975):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)  W / System.err(975):在android.os.Handler.dispatchMessage(Handler.java:99)  W / System.err(975):在android.os.Looper.loop(Looper.java:123)  W / System.err(975):在android.app.ActivityThread.main(ActivityThread.java:4627)  W / System.err(975):at java.lang.reflect.Method.invokeNative(Native Method)  W / System.err(975):at java.lang.reflect.Method.invoke(Method.java:521)  W / System.err(975):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)  W / System.err(975):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)  W / System.err(975):at dalvik.system.NativeStart.main(Native Method)

3 个答案:

答案 0 :(得分:0)

根据faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request.我认为ksoap正在收到一个不是有效的XML soap响应的响应。

您的webservice似乎正在返回Object引用异常。你是否向网络服务发送了正确的参数?

request对象中检查并更正它们。

答案 1 :(得分:0)

我的SOAP调用如下,我认为你省略了命名空间。

List respHeaders = httpTransport.call(NAMESPACE+"/"+methodName, envelope, headerPropertyList);

答案 2 :(得分:0)

此代码适用于尝试它:)在url使用10.0.2.2而不是10.0.2.1因为模拟器正在使用此端口,并且在request.addProperty中,您必须在Web Service ex中编写它时指定方法名称:我的方法是一个字符串m所以我在addProperty中写道(“m”,“//这里是你要发送的对象”)

SoapObject request = new SoapObject("http://tempuri.org/", "GetCoursesInfos");
    request.addProperty("m","courses");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet=true;
    envelope.setOutputSoapObject(request);


    HttpTransportSE http = new HttpTransportSE("http://10.0.2.2:2612/Service1.svc");//hint you

        http.call("http://tempuri.org/IService1/GetCoursesInfos", envelope);

        Object result= (Object)envelope.getResponse();
        message=result.toString();



    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.d("1", "first exe");
        txt.setText(e.getMessage());

    }