0

我正在尝试使用 android 应用程序访问 Web 服务。我收到以下异常,对此我没有任何想法。请帮忙:

09-01 11:21:29.873: WARN/System.err(921): SoapFault - faultcode: 'soapenv:Server' faultstring: 'com.hello.service.DataStore' faultactor: 'null' detail: org.kxml2.kdom.Node@44e9a320
09-01 11:21:29.883: WARN/System.err(921):     at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:112)
09-01 11:21:29.883: WARN/System.err(921):     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)
09-01 11:21:29.883: WARN/System.err(921):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
09-01 11:21:29.883: WARN/System.err(921):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
09-01 11:21:29.883: WARN/System.err(921):     at com.example.HelloTestActivity.onCreate(HelloTestActivity.java:64)
09-01 11:21:29.883: WARN/System.err(921):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-01 11:21:29.883: WARN/System.err(921):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-01 11:21:29.883: WARN/System.err(921):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-01 11:21:29.883: WARN/System.err(921):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-01 11:21:29.883: WARN/System.err(921):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-01 11:21:29.883: WARN/System.err(921):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-01 11:21:29.883: WARN/System.err(921):     at android.os.Looper.loop(Looper.java:123)
09-01 11:21:29.894: WARN/System.err(921):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-01 11:21:29.894: WARN/System.err(921):     at java.lang.reflect.Method.invokeNative(Native Method)
09-01 11:21:29.894: WARN/System.err(921):     at java.lang.reflect.Method.invoke(Method.java:521)
09-01 11:21:29.894: WARN/System.err(921):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-01 11:21:29.894: WARN/System.err(921):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-01 11:21:29.904: WARN/System.err(921):     at dalvik.system.NativeStart.main(Native Method)

该请求甚至没有命中服务器。它仅在调用时失败。以下是我的网络服务调用代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv=(TextView)findViewById(R.id.hello);

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    DataStore t=new DataStore("samsung");


    PropertyInfo pi = new PropertyInfo();
    pi.setName("name");
    pi.setValue(t);
    pi.setType(t.getClass());

    request.addProperty(pi);    
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
        envelope.dotNet=true;
        envelope.setOutputSoapObject(request);
        envelope.setAddAdornments(false);
        envelope.implicitTypes=true;
        envelope.addMapping(NAMESPACE, "DataStore",new DataStore().getClass());
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
        try{
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapObject response=(SoapObject) envelope.getResponse();
            String Name =  response.getProperty(0).toString();
            tv.setText("Response  :" + Name);
            } catch (Exception e) {
                e.printStackTrace();
            }

}

以下是我的java bean:

public class DataStore implements KvmSerializable
{
    private static final String NAMESPACE = "http://service.hello.com";
    private String path;

    public String getPath() {
        return path;
    }

    private void setPath(String path) {
        this.path = path;
    }

    public DataStore(String path) {

        this.path = path;
    }

    public DataStore() {
        // TODO Auto-generated constructor stub
    }

    public Object getProperty(int arg0) {
        Log.d("KVM","gp");

            switch(arg0)
            {
            case 0:
                Log.d("KVM","after");
                return  path;

            }

            return null;
        }

        public int getPropertyCount() {
            Log.d("KVM","gpc");
            return 1;
        }

        public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
            Log.d("KVM","gpi "+index);
            switch(index)
            {
            case 0:
                info.type = PropertyInfo.STRING_CLASS;
                info.name = "path";
                break;

            default:break;
            }
        }


        public void setProperty(int index, Object value) {
            Log.d("KVM","sp");
            switch(index)
            {
            case 0:
                path = (String)value;
                break;

            default:
                break;
            }
        }
        public void register(SoapSerializationEnvelope cm) {
            // TODO Auto-generated method stub
            Log.d("KVM","register");
             cm.addMapping(NAMESPACE, "DataStore", this.getClass());
        }

}

请帮我解决这个问题。

问候, 拉胡尔

4

3 回答 3

1

如果你有soapfault,你需要手动解析答案:(你的例外

catch (Exception e) {
                e.printStackTrace();
            }

我认为您使用的是旧版本的 ksoap2 :( http://code.google.com/p/ksoap2-android/

这给了你答案然后你可以使用 sax 解析器或其他来解析你的答案:

androidHttpTransport.responseDump;

如果您找到其他方法来做这些,请告诉我,我将不胜感激。

于 2011-09-01T07:16:36.907 回答
0

检查您在 android 中的属性名称是否与 Web 服务端相同。

例如 。

PropertyInfo pi = new PropertyInfo();
pi.setName("name");
pi.setValue(t);
pi.setType(t.getClass());

您的参数名称“名称”在 Web 服务方法中可能不同。查看 !

于 2014-06-20T23:11:47.390 回答
0

我使用以下方法:

/**
 * Method to retrieve the errorMessage from the given SoapFault.
 * @param soapFault
 * @return String representing the errorMessage found in the given SoapFault.
 */
private static String getSoapErrorMessage (SoapFault soapFault) {
    String errorMessage;
    try {
        Node detailNode = soapFault.detail;
        Element faultDetailElement = (Element)detailNode.getElement(0).getChild(1);
        Element errorMessageElement = (Element)faultDetailElement.getChild(0);
        errorMessage =  errorMessageElement.getText(0);
    }
    catch (Exception e) {
        e.printStackTrace();
        errorMessage = "Could not determine soap error.";
    }
    return errorMessage;
}
于 2014-05-13T07:59:04.147 回答