【问题标题】:Android Web Service connenction ErrorAndroid Web 服务连接错误
【发布时间】:2013-10-21 12:13:19
【问题描述】:

我创建了 Java Web 服务并尝试连接 android 代码。我正在运行该服务,但 android 应用程序在为命名空间和方法名称创建肥皂对象时显示错误。我做了所有更改,一切都是正确的命名空间、方法名称,URL 都是正确的。但我不知道有什么问题,谁能帮助我...! 我的安卓代码是-----> 显示错误 -“SoapObject 请求 = 新 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();
        }
    }
}

【问题讨论】:

  • 请向我们展示错误信息/堆栈跟踪
  • 您是否将 SoapLibary 包含到您的项目中?
  • @Ion Aalbers 我一开始就这样做了,但我看不到显示一些警报的错误..

标签: android web-services tomcat


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 2023-03-09
    相关资源
    最近更新 更多