【问题标题】:Connecting to external webservice fail to response on Android连接到外部 Web 服务在 Android 上无法响应
【发布时间】:2015-04-25 01:22:01
【问题描述】:

我正在尝试从 Android 应用程序连接到外部 Web 服务,但目前它在 XML 响应上崩溃,请帮助我注意调用结构是否构建不正确或任何响应代码崩溃。这是我的代码:

public class sri extends AsyncTask<String, String, String>
{
public final static String URL = "http://qa-suia.ambiente.gob.ec:8092/suiawebservices/SuiaServices?wsdl";
public static final String NAMESPACE = "http://client.ambiente.gob.ec/";
public static final String SOAP_ACTION_PREFIX = "/";
private static final String METHOD = "getRuc";

private String resp;
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
protected String doInBackground(String... param)
{

    SoapObject request = new SoapObject(NAMESPACE,METHOD);
    //String JsonString=Serializa();
    request.addProperty("user","99999999");
    request.addProperty("pass","xxxxxxxxxxxx");
    request.addProperty("rucNumber","99999999999");

    //sobre.dotNet=true;
    sobre.setOutputSoapObject(request);
    try
    {
        HttpTransportSE transporte=new HttpTransportSE(URL);
        transporte.call(NAMESPACE+METHOD, sobre);
    } catch (Exception e)
    {
        String msn="error";
        return msn;
    }

    try {
        if (sobre != null) {
            SoapPrimitive response = (SoapPrimitive)sobre.getResponse();
            resp=response.toString();

        }
        else
        {

        }
    } catch (Exception e) {
        e.printStackTrace();
        resp = e.getMessage();
    }

    return resp;
}

protected void onProgressUpdate(Integer... values)
{         
}

public void onPreExecute()
{  
}


public void onPostExecute(String result)
{

    String resultado=result;


}

【问题讨论】:

  • 您看到的堆栈跟踪是什么?
  • 你在使用像 ksoap2 这样的外部库吗?
  • @KristyWelsh 是的,目前只使用 ksoap2 和 json

标签: android web-services thread-synchronization


【解决方案1】:

这是我正在调用 .Net 服务的工作代码(看起来您没有将请求放入信封中):

    private static SoapPrimitive callProcServiceForScalar(String serviceMethod, String storedProc, String params) throws Exception {
    String NAMESPACE = "http://" + YourIPAddress + "/";
    String METHOD_NAME = getMethodName(serviceMethod);
    String SOAP_ACTION = NAMESPACE + METHOD_NAME;
    String URL = "http://" + YourIP + "/YourService.asmx";
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


    request.addProperty("sPassword", sYourPassword);
    request.addProperty("sData", sServerDB);
    request.addProperty("sSP_Name", storedProc);
    request.addProperty("sParam", params);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);



    // Enable the below property if consuming .Net service
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);


    numberOfBytesTransmitted = numberOfBytesTransmitted + StringToBytes(request.toString());


    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, timeout);

    SoapPrimitive returnable = null;
    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        returnable = (SoapPrimitive)envelope.getResponse();
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("Msg:" + e.getMessage() + "; SP:" + storedProc + "; Params: " + params + "; Method:" + METHOD_NAME);
    }

    return returnable;
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-07
  • 2012-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-10
相关资源
最近更新 更多