0

我创建了 Java Web 服务并尝试与 android 代码连接。我正在运行该服务,但 android 应用程序在为命名空间和方法名称创建的 soap 对象中显示错误。我做了所有的更改,一切都是正确的命名空间、方法名称、URL一切都是正确的。但我不知道有什么问题可以帮助我......!我的 android 代码是-----> 在 -“SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);”中显示错误

public class RetailerActivity extends Activity {
    private static final String SOAP_ACTION = "urn:training/searchCompanyInfo";
    private static final String METHOD_NAME = "searchCompanyInfo";
    private static final String NAMESPACE = "urn:training/";
    private static final String URL = "http://localhost/attest/CompanyInfoService?wsdl";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        System.out.println(NAMESPACE);
        System.out.println(METHOD_NAME);
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.setOutputSoapObject(request);

        HttpTransportSE ht = new HttpTransportSE(URL);
        try {
            ht.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();


            SoapPrimitive s = response;
            String str = s.toString();
            String resultArr[] = str.split("&");//Result string will split & store in an array

            TextView tv = new TextView(this);

            for(int i = 0; i<resultArr.length;i++){
            tv.append(resultArr[i]+"\n\n");
           }
            setContentView(tv);

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

1 回答 1

0

在Android中,你不能在主线程上进行网络操作,你需要在后台线程中执行你的soap请求。请阅读AsyncTask

于 2013-10-22T04:44:22.533 回答