java - 无法从 Android 中的 Web 服务解析

标签 java android web-services

我在使用此代码时遇到异常,但它适用于其他链接。

public class WebserviceCall {

    static WebserviceCall com;
    String namespace = "http://tempuri.org/";
    private String url = "http://sicsglobal.co.in/T-Drive/WebService_TDrive.asmx";
    String SOAP_ACTION;
    SoapObject request = null, objMessages = null;
    SoapSerializationEnvelope envelope;
    AndroidHttpTransport androidHttpTransport;

    public static WebserviceCall getInstance() {
        if (com == null)
            return new WebserviceCall();
        else
            return com;
    }

    protected void SetEnvelope() {
        try {
            envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            androidHttpTransport = new AndroidHttpTransport(url);
            androidHttpTransport.debug = true;

        } catch (Exception e) {
            System.out.println("Soap Exception SetEnvelope (); \n"
                    + e.toString());
        }
    }

    public String getConvertedWeight(String MethodName, String thisUsername,
            String thisPassword) {
        try {
            SOAP_ACTION = namespace + MethodName;
            request = new SoapObject(namespace, MethodName);

            request.addProperty("userId", "" + thisUsername.trim());
            request.addProperty("password", thisPassword.trim());

            SetEnvelope();

            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                String result = envelope.getResponse().toString();
                return result;
            } catch (Exception e) {
                return e.toString();
            }
        } catch (Exception e) {
            // TODO: handle exception
            return e.toString();
        }
    }

}

最佳答案

您应该准备您的soap请求,然后您可以执行正确的http请求,因为您正在连接的网络服务是一个soap服务,为此您可以使用ksoap2-android准备肥皂请求

也看看这里How to call a SOAP web service on Android

关于java - 无法从 Android 中的 Web 服务解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20540119/

相关文章:

Android Admob android list 错误

JavaFX:加载数据任务与进度条结合

java - 如何在android中不循环获取数组项?

java - 这个日志语句有什么问题?

c# - 您如何管理网络服务的变更?

jquery - 使用 JSON 调用 asmx Web 服务器时出现内部服务器错误

ios - 如何在终止时运行 swift 应用程序?

java - 我应该从可调用类的 call() 方法中抛出异常吗?

android - 即使打开 GPS,位置也为空

android - 帮助新手学习 Eclipse/Android 调试最佳实践